<div class="gmail_quote">On Sat, Dec 12, 2009 at 5:11 PM, Carsten Haese <span dir="ltr"><<a href="mailto:carsten.haese@gmail.com">carsten.haese@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im">Victor Subervi wrote:<br>
> Hi;<br>
> What type does python consider a MySQL Set??<br>
<br>
</div>Let's take a look:<br>
<br>
>>> import MySQLdb<br>
>>> conn = MySQLdb.connect(db="carsten", user="blah", passwd="blah")<br>
>>> cur = conn.cursor()<br>
>>> cur.execute("""<br>
...     create table pizza (<br>
...         id integer,<br>
...         toppings set('cheese','sauce','peperoni','mushrooms')<br>
...     )<br>
... """)<br>
0L<br>
>>> cur.execute("""<br>
...     insert into pizza values(1, 'cheese,sauce,peperoni')<br>
... """)<br>
1L<br>
>>> cur.execute("select * from pizza")<br>
1L<br>
>>> rows = cur.fetchall()<br>
>>> toppings = rows[0][1]<br>
>>> print toppings<br>
cheese,sauce,peperoni<br>
>>> print type(toppings)<br>
<type 'str'><br>
<br>
<br>
Looks like a string to me.<br></blockquote><div><br>Yep, sure does, but it isn't. Again:<br><br>              if isinstance(colValue[0], (str, int, long, float, long, complex, unicode, list, buffer, xrange, tuple)):<br>
                pass<br>              else:<br>
                print 'XXX'<br><br>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.<br>
V<br></div></div>