blob: ee2d39f15a5f14a97db1885af42eaf5d0c272e51 [file] [log] [blame]
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00001\section{Built-in Module \sectcode{dbm}}
2\bimodindex{dbm}
3
Guido van Rossum0bf84751995-07-07 22:55:57 +00004The \code{dbm} module provides an interface to the {\UNIX}
5\code{(n)dbm} library. Dbm objects behave like mappings
6(dictionaries), except that keys and values are always strings.
7Printing a dbm object doesn't print the keys and values, and the
8\code{items()} and \code{values()} methods are not supported.
9
10See also the \code{gdbm} module, which provides a similar interface
11using the GNU GDBM library.
12\bimodindex{gdbm}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000013
14The module defines the following constant and functions:
15
16\renewcommand{\indexsubitem}{(in module dbm)}
17\begin{excdesc}{error}
18Raised on dbm-specific errors, such as I/O errors. \code{KeyError} is
19raised for general mapping errors like specifying an incorrect key.
20\end{excdesc}
21
Guido van Rossum0bf84751995-07-07 22:55:57 +000022\begin{funcdesc}{open}{filename\, \optional{flag\, \optional{mode}}}
23Open a dbm database and return a dbm object. The \var{filename}
24argument is the name of the database file (without the \file{.dir} or
25\file{.pag} extensions).
26
27The optional \var{flag} argument can be
28\code{'r'} (to open an existing database for reading only --- default),
29\code{'w'} (to open an existing database for reading and writing),
30\code{'c'} (which creates the database if it doesn't exist), or
31\code{'n'} (which always creates a new empty database).
32
33The optional \var{mode} argument is the \UNIX{} mode of the file, used
34only when the database has to be created. It defaults to octal
35\code{0666}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000036\end{funcdesc}