blob: 8f647281db7bc04fdc9329b956792bf1ed0e5717 [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 Drakeb91e9341998-07-23 17:59:49 +00005\modulesynopsis{The standard ``database'' interface, based on ndbm.}
6
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00007
Fred Drakebbac4321999-02-20 00:14:17 +00008The \module{dbm} module provides an interface to the \UNIX{}
Guido van Rossum0bf84751995-07-07 22:55:57 +00009\code{(n)dbm} library. Dbm objects behave like mappings
10(dictionaries), except that keys and values are always strings.
11Printing a dbm object doesn't print the keys and values, and the
12\code{items()} and \code{values()} methods are not supported.
13
Fred Drakebbac4321999-02-20 00:14:17 +000014See also the \refmodule{gdbm}\refbimodindex{gdbm} module, which
15provides a similar interface using the GNU GDBM library.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000016
17The module defines the following constant and functions:
18
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000019\begin{excdesc}{error}
Fred Drakebbac4321999-02-20 00:14:17 +000020Raised on dbm-specific errors, such as I/O errors.
21\exception{KeyError} is raised for general mapping errors like
22specifying an incorrect key.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000023\end{excdesc}
24
Fred Drakecce10901998-03-17 06:33:25 +000025\begin{funcdesc}{open}{filename, \optional{flag, \optional{mode}}}
Guido van Rossum0bf84751995-07-07 22:55:57 +000026Open a dbm database and return a dbm object. The \var{filename}
27argument is the name of the database file (without the \file{.dir} or
28\file{.pag} extensions).
29
30The optional \var{flag} argument can be
31\code{'r'} (to open an existing database for reading only --- default),
32\code{'w'} (to open an existing database for reading and writing),
33\code{'c'} (which creates the database if it doesn't exist), or
34\code{'n'} (which always creates a new empty database).
35
36The optional \var{mode} argument is the \UNIX{} mode of the file, used
37only when the database has to be created. It defaults to octal
38\code{0666}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000039\end{funcdesc}