[python-nl] while-lus vraagje
rr at nederhoed.com
rr at nederhoed.com
Mon Mar 13 16:32:22 CET 2006
(attachment is inclusief doctest)
Ach, als we dan toch bezig zijn:
class ResultSetIterator:
""" Itereer over een result set van een query mbv een klasse """
def __init__(self, result_set):
"""Constructor """
self.rs = result_set
def next(self):
"""Iterator """
while True:
result = self.rs.fetchone()
if result is not None:
yield result
else:
raise StopIteration
def __iter__(self):
return self.next()
# in programma:
for row in ResultSetIterator(rs):
print row
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ResultSetIterator.py
Type: text/x-python
Size: 921 bytes
Desc: not available
Url : http://mail.python.org/pipermail/python-nl/attachments/20060313/961d7f12/attachment.py
More information about the Python-nl
mailing list