Another Sets Problem

Stefan Behnel stefan_ml at behnel.de
Tue Dec 29 17:46:02 EST 2009


> Victor Subervi wrote:
>> I'm using python 2.4.3 which apparently requires that I import Set:
>> from sets import Set

... unless you use "set" instead of "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)):

This line leaves me baffled. I guess a positive list would be less ugly 
here, and some more generic code that handles data values regardless of 
their exact type would be even better.

>>               html = "<b>%s</b>: <select name='%s'>" % (col, col)

Note that there are tons of helpful libraries out there for generating HTML 
with Python. While string concatenation works in general, it also makes it 
very hard to get the output right, and to keep the output correct when you 
change minor stuff in your code.

Given that you seem to pull data from a database into a web page, you might 
want to take a look at Django, for example.

Stefan



More information about the Python-list mailing list