blob: 2efa6e0d3a87bd578acc11cdca905600384b5a18 [file] [log] [blame]
Fred Drake295da241998-08-10 19:42:37 +00001\section{\module{dbm} ---
2 The standard ``database'' interface, based on ndbm.}
Fred Drakeb91e9341998-07-23 17:59:49 +00003\declaremodule{builtin}{dbm}
4
5\modulesynopsis{The standard ``database'' interface, based on ndbm.}
6
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00007
Fred Drake4b3f0311996-12-13 22:04:31 +00008The \code{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
14See also the \code{gdbm} module, which provides a similar interface
15using the GNU GDBM library.
Fred Drake4f496cc1997-12-16 04:08:24 +000016\refbimodindex{gdbm}
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}
21Raised on dbm-specific errors, such as I/O errors. \code{KeyError} is
22raised for general mapping errors like specifying an incorrect key.
23\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}