Assignment in a while?

Ant antroy at gmail.com
Sun Apr 2 15:17:20 EDT 2006


There are various ways you could do this:

If the number of results won't be too big:

...
for result in sth.fetchall():
    print result

If it may be very large:
...

result = sth.fetchone()
while result:
    print result
    result = sth.fetchone()

Or perhaps nicer:

...
def result_iterator(result_set):
    yield result_set.fetchone()

for result in result_iterator(sth):
    print result

HTH.




More information about the Python-list mailing list