#########################################33 #! /usr/bin/env python import MySQLdb db=MySQLdb.connect(host='localhost', db='photum_0_6_2', user='root', passwd='thkhgfgd') c=db.cursor() c.execute('select person from persons order by person') for (person,) in c: # or c.fetchall() (may be more portable) print person ################################################
If you return more than one column, then you don't need the parentheses for the tuple unpacking. MySQLdb (and all other DB API databases) return rows as tuples, so if you only select one column, you get a tuple of one item. (google groups eats leading spaces) -- http://mail.python.org/mailman/listinfo/python-list