Next: termios Prev: dbm Up: UNIX Specific Services Top: Top

8.6. Built-in Module gdbm

Gdbm provides python programs with an interface to the GNU gdbm database library. Gdbm objects are of the mapping type, so they can be handled just like objects of the built-in dictionary type, except that keys and values are always strings, and printing a gdbm object doesn't print the keys and values.

The module is based on the Dbm module, modified to use GDBM instead.

The module defines the following constant and functions:

error -- exception of module gdbm
Raised on gdbm-specific errors, such as I/O errors. KeyError is raised for general mapping errors like specifying an incorrect key.
open (filename, rwmode, filemode) -- function of module gdbm
Open a gdbm database and return a mapping object. filename is the name of the database file, rwmode is 'r', 'w', 'c', or 'n' for reader, writer (this also gives read access), create (writer, but create the database if it doesn't already exist) and newdb (which will always create a new database). Only one writer may open a gdbm file and many readers may open the file. Readers and writers cannot open the gdbm file at the same time. Note that the GDBM_FAST mode of opening the database is not supported. filemode is the UNIX mode of the file, used only when a database is created (but to be supplied at all times).