open and close calls in factto your codea shelve really does appear to be persistent dictionary of persistent objectspython does all the work of mapping its content to and from file for instanceexample - shows how to store our in-memory dictionary objects in shelve for permanent keeping example - pp \preview\make_db_shelve py from initdata import bobsue import shelve db shelve open('people-shelve'db['bob'bob db['sue'sue db close(this script creates one or more files in the current directory with the name peopleshelve as prefix (in python on windowspeople-shelve bakpeople-shelve datand people-shelve diryou shouldn' delete these files (they are your database!)and you should be sure to use the same base name in other scripts that access the shelve example - for instancereopens the shelve and indexes it by key to fetch its stored records example - pp \preview\dump_db_shelve py import shelve db shelve open('people-shelve'for key in dbprint(key'=>\ 'db[key]print(db['sue']['name']db close(we still have dictionary of dictionaries herebut the top-level dictionary is really shelve mapped onto file much happens when you access shelve' keys--it uses pickle internally to serialize and deserialize objects storedand it interfaces with keyed-access filesystem from your perspectivethoughit' just persistent dictionary example - shows how to code shelve updates example - pp \preview\update_db_shelve py from initdata import tom import shelve db shelve open('people-shelve'sue db['sue'sue['pay'* db['sue'sue db['tom'tom db close(fetch sue update sue add new record notice how this code fetches sue by keyupdates in memoryand then reassigns to the key to update the shelvethis is requirement of shelves by defaultbut not always of more advanced shelve-like systems such as zodbcovered in as we'll see sneak preview