Another Sets Problem

Victor Subervi victorsubervi at gmail.com
Mon Dec 28 13:05:50 EST 2009


On Mon, Dec 28, 2009 at 1:41 PM, MRAB <python at 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*.

>
>
>                   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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20091228/5e1cc999/attachment.html>


More information about the Python-list mailing list