blob: a84f987645c36fa9345242f5a798ea16b5e7c6ed [file] [log] [blame]
Fred Drake295da241998-08-10 19:42:37 +00001\section{\module{dbm} ---
Fred Drakebbac4321999-02-20 00:14:17 +00002 Simple ``database'' interface}
Fred Drakeb91e9341998-07-23 17:59:49 +00003
Fred Drakebbac4321999-02-20 00:14:17 +00004\declaremodule{builtin}{dbm}
Fred Drakea54a8871999-03-02 17:03:42 +00005 \platform{Unix}
Fred Drakeb91e9341998-07-23 17:59:49 +00006\modulesynopsis{The standard ``database'' interface, based on ndbm.}
7
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00008
Fred Drakebbac4321999-02-20 00:14:17 +00009The \module{dbm} module provides an interface to the \UNIX{}
Guido van Rossum0bf84751995-07-07 22:55:57 +000010\code{(n)dbm} library. Dbm objects behave like mappings
11(dictionaries), except that keys and values are always strings.
12Printing a dbm object doesn't print the keys and values, and the
Fred Drakef6863c11999-03-02 16:37:17 +000013\method{items()} and \method{values()} methods are not supported.
Guido van Rossum0bf84751995-07-07 22:55:57 +000014
Fred Drakebbac4321999-02-20 00:14:17 +000015See also the \refmodule{gdbm}\refbimodindex{gdbm} module, which
16provides a similar interface using the GNU GDBM library.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000017
18The module defines the following constant and functions:
19
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000020\begin{excdesc}{error}
Fred Drakebbac4321999-02-20 00:14:17 +000021Raised on dbm-specific errors, such as I/O errors.
22\exception{KeyError} is raised for general mapping errors like
23specifying an incorrect key.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000024\end{excdesc}
25
Fred Drakecce10901998-03-17 06:33:25 +000026\begin{funcdesc}{open}{filename, \optional{flag, \optional{mode}}}
Guido van Rossum0bf84751995-07-07 22:55:57 +000027Open a dbm database and return a dbm object. The \var{filename}
28argument is the name of the database file (without the \file{.dir} or
29\file{.pag} extensions).
30
31The optional \var{flag} argument can be
32\code{'r'} (to open an existing database for reading only --- default),
33\code{'w'} (to open an existing database for reading and writing),
34\code{'c'} (which creates the database if it doesn't exist), or
35\code{'n'} (which always creates a new empty database).
36
37The optional \var{mode} argument is the \UNIX{} mode of the file, used
38only when the database has to be created. It defaults to octal
39\code{0666}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000040\end{funcdesc}
Fred Drake4f21d541999-04-05 22:18:12 +000041
42
43\begin{seealso}
44 \seemodule{anydbm}{Generic interface to \code{dbm}-style databases.}
45 \seemodule{whichdb}{Utility module used to determine the type of an
46 existing database.}
47\end{seealso}