Another Sets Problem
Victor Subervi
victorsubervi at gmail.com
Mon Dec 28 14:15:14 EST 2009
On Mon, Dec 28, 2009 at 3:07 PM, Steve Holden <steve at holdenweb.com> wrote:
> Victor Subervi wrote:
> > On Mon, Dec 28, 2009 at 1:41 PM, MRAB <python at mrabarnett.plus.com
> > <mailto: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*.
> >
> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20091228/9e66c8ca/attachment-0001.html>
More information about the Python-list
mailing list