I l@ve RuBoard Previous Section Next Section

10.8 The gdbm Module

(Optional) The gdbm module provides an interface to the GNU dbm database handler, as Example 10-8 shows.

Example 10-8. Using the gdbm Module
File: gdbm-example-1.py

import gdbm

db = gdbm.open("gdbm", "c")
db["1"] = "call"
db["2"] = "the"
db["3"] = "next"
db["4"] = "defendant"
db.close()


db = gdbm.open("gdbm", "r")

keys = db.keys()
keys.sort()
for key in keys:
    print db[key],

call the next defendant
    I l@ve RuBoard Previous Section Next Section