Finally . . . generators in Jython
Apr 4th, 20071 Comment
Okay, so I’m behind the Eight Ball. But I’m using Jython 2.2b1 and finally had a reason to use generators. Of course, we are back in 2.2-land, so our first line is this:
from __future__ import generators
Then here is my function. Generators are very nice for processes the result of a SQL query!
def getResults():
conn = getConnection()
cur = conn.cursor()
cur.execute("select * from table")
ret = cur.fetchone()
while ret!=None:
yield ret
ret = cur.fetchone()
cur.close()

Oh yes – Finally!
Phew!