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 __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()
One Response to “Finally . . . generators in Jython”
Leave a Reply
You must be logged in to post a comment.