[Newbie] Strange output from list

Gilles Ganault nospam at nospam.com
Tue Nov 11 03:56:08 EST 2008


On Mon, 10 Nov 2008 20:02:39 -0600, Andrew <alif016 at gmail.com> wrote:
>sql = 'SELECT id FROM master'
>rows=list(cursor.execute(sql))
>for id in rows:
>	sql = 'SELECT COUNT(code) FROM companies WHERE code="%s"' % id[0]
>	result = list(cursor.execute(sql))
>	print "Code=%s, number=%s" % (id[0],result[0][0])
>Notice the extra [0] index on the "result" 
>
>In English:
>Item zero of the tuple that is item zero of result

Thanks, it worked. But why does "id[0]" return the value of the first
(and only) column as I expected it, while I need to use "result[0]
[0]" to access the first column?



More information about the Python-list mailing list