Perl to Python using MqSQLdb

Fredrik Lundh fredrik at pythonware.com
Wed Aug 13 09:55:36 EDT 2008


Jeroen Ruigrok van der Werven wrote:

>> cursor=db.cursor()
>> cursor.execute(sql)
>> while (1):
>> 	row = cursor.fetchone()
>> 	if row == None:
>> 		break
>> 	combined = ', '.join(row)
> 
> Why not something like:
> 
> for row in cursor.fetchall():
>     combined = ', '.join(row)

which can be written as

      combined = ', '.join(cursor.fetchall())

but probably won't work, since fetchall() returns a sequence of tuples, 
unless I'm mistaken.  Try something like this instead:

      combined = ', '.join(row[0] for row in cursor.fetchall())

</F>




More information about the Python-list mailing list