Manipulating MySQL Sets
Carsten Haese
carsten.haese at gmail.com
Sat Dec 12 18:35:55 EST 2009
Victor Subervi wrote:
> PS:
>
> Changed the code to this:
>
> elif col[:3] != 'pic':
> if isinstance(colValue[0], (str, int, long, float, long,
> complex, unicode, list, buffer, xrange, tuple)):
> pass
> else:
> print 'XXX'
> if col == 'sizes': # One of those lovely sets
> print colValue[0][0]
>
>
> throws this lovely error:
>
> /var/www/html/angrynates.com/cart/display.py
> <http://angrynates.com/cart/display.py>
> 96 raise
> 97 cursor.close()
> 98 bottom()
> 99
> 100 display()
> display = <function display>
> /var/www/html/angrynates.com/cart/display.py
> <http://angrynates.com/cart/display.py> in display()
> 50 print 'XXX'
> 51 if col == 'sizes':
> 52 print colValue[0][0]
> 53 # ourValue = string.split(colValue[0][6:-3], "','")
> 54 # print ourValue
> colValue = (Set(['Small', 'Extra-small', 'Medium']),)
>
> TypeError: unindexable object
> args = ('unindexable object',)
The traceback helpfully shows us that colValue is a 1-tuple whose zeroth
entry, colValue[0], is an actual bona-fide Python Set object. Such
objects aren't indexable, because sets are unordered. That still doesn't
tell us where colValue is coming from, though, so why it is a Python Set
object when you expected it to be a string remains an unsolved mystery.
--
Carsten Haese
http://informixdb.sourceforge.net
More information about the Python-list
mailing list