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