Another Sets Problem

MRAB python at mrabarnett.plus.com
Mon Dec 28 12:41:15 EST 2009


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.)

>                   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?



More information about the Python-list mailing list