Changing Objects in a Shelve File : shelve « Database « Python Tutorial






import shelve

newtimes = ["110pm", "220pm", "300pm", "445pm"]

db = shelve.open("shelved.dat", "w", writeback=1)

for k in db.keys():
    obj = db[k]
    print "%s: %s" % (k, obj)

flights = db['flights']
times = db['times']

flights['1145'] = "Dallas"
flights['1709'] = "Orlando"

db['times'] = newtimes

db['oldtimes'] = times

db.sync()

for k in db.keys():
    obj = db[k]
    print "%s: %s" % (k, obj)

db.close()








15.5.shelve
15.5.1.object returned by shelve.open is not an ordinary mapping
15.5.2.Storing Objects in a Shelve File
15.5.3.Changing Objects in a Shelve File
15.5.4.Writing to shelve file.
15.5.5.Reading a shelve file.
15.5.6.database based on shelve file