May 2001
Intermediate to advanced
304 pages
6h 12m
English
(Optional) The dbm module provides an interface to the
dbm database handler (available on many Unix
platforms). This is shown in Example 10-6.
Example 10-6. Using the dbm Module
File: dbm-example-1.py
import dbm
db = dbm.open("dbm", "c")
db["first"] = "bruce"
db["second"] = "bruce"
db["third"] = "bruce"
db["fourth"] = "bruce"
db["fifth"] = "michael"
db["fifth"] = "bruce" # overwrite
db.close()
db = dbm.open("dbm", "r")
for key in db.keys():
print repr(key), repr(db[key])
'first' 'bruce'
'second' 'bruce'
'fourth' 'bruce'
'third' 'bruce'
'fifth' 'bruce'Read now
Unlock full access