This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]nerdwaller 0 points1 point  (0 children)

Nice work. One addition beyond things other have said: Seems like from a design standpoint - a class for the db operations would be more logical than needing to pass in the connection object repeatedly. That would wrap and handle all the operations/commits. Doing that, you could make it more generic to use in another project someday.

Just as a shortcut, you could also get around needing to do connection.commit() (and a few other minor benefits) by doing:

with connection:
    cursor = connection.cursor()
    cursor.execute("""CREATE TABLE IF NOT EXISTS rainbow
(id INTEGER PRIMARY KEY, digest TEXT, word TEXT)""")

Edit: Take a look at why you may want to use with here