Finally . . . generators in Jython
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 <strong>future</strong> import generators
Then here is my function. Generators are very nice for processes the result of a SQL query!
</p>
<p>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()
April 4th, 2007 at 7:16 pm
Oh yes - Finally!
Phew!