blob: b7ee6477a3bfa26f946ae62303906f45f1d22f08 [file] [log] [blame]
Fred Drake3a0351c1998-04-04 07:23:21 +00001\section{Built-in Module \module{dbm}}
Fred Drakeb91e9341998-07-23 17:59:49 +00002\declaremodule{builtin}{dbm}
3
4\modulesynopsis{The standard ``database'' interface, based on ndbm.}
5
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00006
Fred Drake4b3f0311996-12-13 22:04:31 +00007The \code{dbm} module provides an interface to the \UNIX{}
Guido van Rossum0bf84751995-07-07 22:55:57 +00008\code{(n)dbm} library. Dbm objects behave like mappings
9(dictionaries), except that keys and values are always strings.
10Printing a dbm object doesn't print the keys and values, and the
11\code{items()} and \code{values()} methods are not supported.
12
13See also the \code{gdbm} module, which provides a similar interface
14using the GNU GDBM library.
Fred Drake4f496cc1997-12-16 04:08:24 +000015\refbimodindex{gdbm}
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}
20Raised on dbm-specific errors, such as I/O errors. \code{KeyError} is
21raised for general mapping errors like specifying an incorrect key.
22\end{excdesc}
23
Fred Drakecce10901998-03-17 06:33:25 +000024\begin{funcdesc}{open}{filename, \optional{flag, \optional{mode}}}
Guido van Rossum0bf84751995-07-07 22:55:57 +000025Open a dbm database and return a dbm object. The \var{filename}
26argument is the name of the database file (without the \file{.dir} or
27\file{.pag} extensions).
28
29The optional \var{flag} argument can be
30\code{'r'} (to open an existing database for reading only --- default),
31\code{'w'} (to open an existing database for reading and writing),
32\code{'c'} (which creates the database if it doesn't exist), or
33\code{'n'} (which always creates a new empty database).
34
35The optional \var{mode} argument is the \UNIX{} mode of the file, used
36only when the database has to be created. It defaults to octal
37\code{0666}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000038\end{funcdesc}