Skip to content

Instantly share code, notes, and snippets.

@absurd
Last active December 17, 2015 04:49
Show Gist options
  • Save absurd/5553519 to your computer and use it in GitHub Desktop.
Save absurd/5553519 to your computer and use it in GitHub Desktop.
There's probably a better idiom for wrapping an sql cursor iterator in a generator function.
def foo():
conn = sqlite3.connect(DATABASE_FILENAME)
c = conn.cursor()
c.execute(SQL_QUERY)
output = True
while output:
output = c.fetchone()
if output:
yield output
else:
conn.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment