On Mon, Dec 28, 2009 at 3:07 PM, Steve Holden <st...@holdenweb.com> wrote:
> Victor Subervi wrote: > > On Mon, Dec 28, 2009 at 1:41 PM, MRAB <pyt...@mrabarnett.plus.com > > <mailto:pyt...@mrabarnett.plus.com>> wrote: > > > > Victor Subervi wrote: > > > > Hi; > > I'm using python 2.4.3 which apparently requires that I import > Set: > > from sets import Set > > I've done this. In another script I successfully manipulated > > MySQL sets by so doing. Here's the code snippet from the script > > where I was able to call the elements in a for loop: > > > > if isinstance(colValue[0], (str, int, float, long, > > complex, unicode, list, buffer, xrange, tuple)): > > pass > > else: > > try: > > html = "<b>%s</b>: <select name='%s'>" % (col, col) > > notSet = 0 > > for itm in colValue[0]: > > try: > > color, number = itm.split(':') > > html += "<option name='%s'>%s</option>" % (itm, > > color) > > except: > > > > > > DON'T USE BARE EXCEPTS! > > > > (There are 2 in your code.) > > > > > > There are times when they are *necessary*. > > > Perhaps so, although it's extremely difficult to think of one since the > exceptions were rationalised. Do you *really* want to catch the > exception that occurs when the user tries to stop the program with a > Control-C? Usually nowadays you want > > except Exception: > > as the "widest" specification. You don't *normally* want to catch > SystemExit, KeyboardInterrupt or GeneratorException. > > > > > > > html += "<option name='%s'>%s</option>" % (itm, > > itm) > > However, when I try that in my current script, the script > > fails. It throws no error, but rather just quits printing to the > > screen. Here's the code snippet: > > > > elif types[x][0:3] == 'set': > > for f in field: > > print '<td>%s</td>\n' % (field) > > else: > > print '<td>%s</td>\n' % (field) > > > > [snip] > > > > You're printing the entire field for each value in the field. Is this > > intentional? > > > > > > It doesn't matter. The code ceases to execute with the line: > > > > for f in field: > > beno > > > Well it looks to me like types[x][0:3] == 'set' and f is empty. That > wouldn't produce any printed output. > It's not empty. I've printed it. But if it were, it would look like this: set([]) and so this would be left to print: ([]) beno
-- http://mail.python.org/mailman/listinfo/python-list