MySQL set and enum, calling values

Victor Subervi victorsubervi at gmail.com
Fri Dec 11 13:08:29 EST 2009


Hi;
I have the following code:

cursor.execute('describe %s;' % store)
colFields, colFieldValues = [itm[0] for itm in cursor], [itm[1] for itm in
cursor]
...
for col in colFields:
...
    print '<b>%s: </b>%s<br />\n' % (col, colValue[0])

Don't worry about the colValue[0]. In fact, the code throws no errors.
However, when colValue[0] (which is called from the MySQL table) is a set as
opposed to, say, a string, it prints out:
Set([])
which is natural, because there isn't anything in the set. What I'm trying
to accomplish, however, is to offer a select of the possible values of that
set as are available from the describe and caught in the tuple
colFieldValues. For example, if I go to print, say, colFieldValues[20],
which is a set, it prints out the whole set:
set('Extra-small','Small','Medium','Large','XLarge','XXLarge','XXXLarge')
But if I print out colFieldValues[20][0], it prints out "s". Now, I suppose
I could do something like lop off the ends of colFieldValues[20] thus:
tmp = string.split(colFieldValues[20][4:-2], "','")
but boy that's inelegant! Any better suggestions? Also, how can I test for
it? It's an instance of string. How do I know if it's a set?
TIA,
Victor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20091211/9820d3c0/attachment-0001.html>


More information about the Python-list mailing list