blob: ac5343f6d98a650cb07d753b10bd4c0b2163688e [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.
Fred Drake4f496cc1997-12-16 04:08:24 +000013\refbimodindex{gdbm}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000014
15The module defines the following constant and functions:
16
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000017\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
Fred Drakecce10901998-03-17 06:33:25 +000022\begin{funcdesc}{open}{filename, \optional{flag, \optional{mode}}}
Guido van Rossum0bf84751995-07-07 22:55:57 +000023Open 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}