Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 1 | \section{Built-in Module \sectcode{dbm}} |
| 2 | \bimodindex{dbm} |
| 3 | |
Guido van Rossum | 0bf8475 | 1995-07-07 22:55:57 +0000 | [diff] [blame] | 4 | The \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. |
| 7 | Printing a dbm object doesn't print the keys and values, and the |
| 8 | \code{items()} and \code{values()} methods are not supported. |
| 9 | |
| 10 | See also the \code{gdbm} module, which provides a similar interface |
| 11 | using the GNU GDBM library. |
| 12 | \bimodindex{gdbm} |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 13 | |
| 14 | The module defines the following constant and functions: |
| 15 | |
| 16 | \renewcommand{\indexsubitem}{(in module dbm)} |
| 17 | \begin{excdesc}{error} |
| 18 | Raised on dbm-specific errors, such as I/O errors. \code{KeyError} is |
| 19 | raised for general mapping errors like specifying an incorrect key. |
| 20 | \end{excdesc} |
| 21 | |
Guido van Rossum | 0bf8475 | 1995-07-07 22:55:57 +0000 | [diff] [blame] | 22 | \begin{funcdesc}{open}{filename\, \optional{flag\, \optional{mode}}} |
| 23 | Open a dbm database and return a dbm object. The \var{filename} |
| 24 | argument is the name of the database file (without the \file{.dir} or |
| 25 | \file{.pag} extensions). |
| 26 | |
| 27 | The 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 | |
| 33 | The optional \var{mode} argument is the \UNIX{} mode of the file, used |
| 34 | only when the database has to be created. It defaults to octal |
| 35 | \code{0666}. |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 36 | \end{funcdesc} |