Shelve, or how to create a database app with Python (and tkinter)

Create a database

With the shelve module we can use in the simpliest way a database that we can handle just easy as is easy to use a dictionary. In fact when we import the shelve module, that is a built-in module, you do not have to install anything apart Python, we create a db object creating a reference to the file like:

s = shelve.open(“database.db”)

Now, you can add your key to the database just like in a dictionary, like this:

s[‘key1’] = 100

"""Create a database

svelve is the module to create it
"""

import shelve

s = shelve.open("students.db")
s.close()

Published by pythonprogramming

Started with basic on the spectrum, loved javascript in the 90ies and python in the 2000, now I am back with python, still making some javascript stuff when needed.