Last active
December 17, 2015 04:49
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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