Bare Excepts

Victor Subervi victorsubervi at gmail.com
Wed Dec 30 05:09:29 EST 2009


Hi;
I'll trouble-shoot bare excepts as I work on new code. I'll trouble-shoot
the others that don't (seem to) cause problems later. Here's a new one:

    for optionsStore, storeOptions in ourOptions().iteritems():
      if store == optionsStore:
        for option in storeOptions:
          try:
            fromForm = form.getfirst(option)
            try:
              fromForm, junk = string.split(fromForm, ':')
            except:
              pass # This is only an expedient to split options that have a
colon in them, such as the colors
            fromForm = string.replace(fromForm, '-', '')
            sql = 'select "%s" from %s%s t join %s p where p.ID=t.ID;' %
(fromForm, store, (option[0].upper() + option[1:]), store)
#            print sql
            cursor.execute(sql)
            try:
              optionsPrices += cursor.fetchone()[0]
            except TypeError:
              pass # There is no options price for this.
          except:
            raise

If there are no values entered into table (in this case "productsSizes") for
the given product ID, then "optionsPrices" should not be added unto. Am I
doing this correctly? Or is there a better way than capturing ALL
TypeErrors?
TIA,
beno
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20091230/c7f97a03/attachment.html>


More information about the Python-list mailing list