Toggle navigation

dumbdbm --- Portable DBM implementation

dumbdbm --- Portable DBM implementation

The dumbdbm module provides a persistent dictionary-like interface which is written entirely in Python. Unlike other modules such as gdbm and bsddb, no external library is required. As with other persistent mappings, the keys and values must always be strings.

The module defines the following:

exception dumbdbm.error

Raised on dumbdbm-specific errors, such as I/O errors. KeyError is raised for general mapping errors like specifying an incorrect key.

dumbdbm.open(filename[, flag[, mode]])[source]

Open a dumbdbm database and return a dumbdbm object. The filename argument is the basename of the database file (without any specific extensions). When a dumbdbm database is created, files with .dat and .dir extensions are created.

The optional flag argument is currently ignored; the database is always opened for update, and will be created if it does not exist.

The optional mode argument is the Unix mode of the file, used only when the database has to be created. It defaults to octal 0666 (and will be modified by the prevailing umask).

Changed in version 2.2: The mode argument was ignored in earlier versions.

In addition to the dictionary-like methods, dumbdm objects provide the following method:

dumbdbm.close()

Close the dumbdm database.

Dumbdbm Objects

In addition to the methods provided by the UserDict.DictMixin class, dumbdbm objects provide the following methods.

dumbdbm.sync()

Synchronize the on-disk directory and data files. This method is called by the sync() method of Shelve objects.