Manipulating MySQL Sets

Victor Subervi victorsubervi at gmail.com
Sat Dec 12 18:07:12 EST 2009


On Sat, Dec 12, 2009 at 5:11 PM, Carsten Haese <carsten.haese at gmail.com>wrote:

> Victor Subervi wrote:
> > Hi;
> > What type does python consider a MySQL Set??
>
> Let's take a look:
>
> >>> import MySQLdb
> >>> conn = MySQLdb.connect(db="carsten", user="blah", passwd="blah")
> >>> cur = conn.cursor()
> >>> cur.execute("""
> ...     create table pizza (
> ...         id integer,
> ...         toppings set('cheese','sauce','peperoni','mushrooms')
> ...     )
> ... """)
> 0L
> >>> cur.execute("""
> ...     insert into pizza values(1, 'cheese,sauce,peperoni')
> ... """)
> 1L
> >>> cur.execute("select * from pizza")
> 1L
> >>> rows = cur.fetchall()
> >>> toppings = rows[0][1]
> >>> print toppings
> cheese,sauce,peperoni
> >>> print type(toppings)
> <type 'str'>
>
>
> Looks like a string to me.
>

Yep, sure does, but it isn't. Again:

              if isinstance(colValue[0], (str, int, long, float, long,
complex, unicode, list, buffer, xrange, tuple)):
                pass
              else:
                print 'XXX'

and those "strings" printed triple-X. It ain't no string. Besides, if it
were a string, I'd be able to slice it, wouldn't I? Can't slice it either.
V
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20091212/06ae9991/attachment-0001.html>


More information about the Python-list mailing list