I l@ve RuBoard Previous Section Next Section

10.7 The dumbdbm Module

The dumbdbm module, shown in Example 10-7, is a very simple database implementation, similar to dbm and friends, but written in pure Python. It uses two files: a binary file (.dat), which contain the data, and a text file (.dir), which contains data descriptors.

Example 10-7. Using the dumbdbm Module
File: dumbdbm-example-1.py

import dumbdbm

db = dumbdbm.open("dumbdbm", "c")
db["first"] = "fear"
db["second"] = "surprise"
db["third"] = "ruthless efficiency"
db["fourth"] = "an almost fanatical devotion to the Pope"
db["fifth"] = "nice red uniforms"
db.close()

db = dumbdbm.open("dumbdbm", "r")
for key in db.keys():
    print repr(key), repr(db[key])

'first' 'fear'
'third' 'ruthless efficiency'
'fifth' 'nice red uniforms'
'second' 'surprise'
'fourth' 'an almost fanatical devotion to the Pope'
    I l@ve RuBoard Previous Section Next Section