Problem with sqlite3 cursor and imbricated for loop

jhermann Juergen.Hermann at 1und1.de
Wed Nov 19 06:31:39 EST 2008


c.execute("select * from stocks")
for s in list(c):
   print s[0]
   c.execute("select * from stocks where price<20")
   for sp in c:
      print '  '+sp[0]
c.close()

The simple addition of list() should do away with the dependency on
mysql's implementation, since it forces the instant fetch of all data.
Whether that is better than to use a 2nd cursor is probably a matter
of taste.

Using "*" in selects is always bad, though. ;)



More information about the Python-list mailing list