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()

One Response to “Finally . . . generators in Jython”

  1. Nubi Says:

    Oh yes - Finally!

    Phew!

Leave a Reply

You must be logged in to post a comment.