Fred Drake | 3a0351c | 1998-04-04 07:23:21 +0000 | [diff] [blame] | 1 | \section{Built-in Module \module{dbm}} |
Fred Drake | b91e934 | 1998-07-23 17:59:49 +0000 | [diff] [blame] | 2 | \declaremodule{builtin}{dbm} |
| 3 | |
| 4 | \modulesynopsis{The standard ``database'' interface, based on ndbm.} |
| 5 | |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 6 | |
Fred Drake | 4b3f031 | 1996-12-13 22:04:31 +0000 | [diff] [blame] | 7 | The \code{dbm} module provides an interface to the \UNIX{} |
Guido van Rossum | 0bf8475 | 1995-07-07 22:55:57 +0000 | [diff] [blame] | 8 | \code{(n)dbm} library. Dbm objects behave like mappings |
| 9 | (dictionaries), except that keys and values are always strings. |
| 10 | Printing a dbm object doesn't print the keys and values, and the |
| 11 | \code{items()} and \code{values()} methods are not supported. |
| 12 | |
| 13 | See also the \code{gdbm} module, which provides a similar interface |
| 14 | using the GNU GDBM library. |
Fred Drake | 4f496cc | 1997-12-16 04:08:24 +0000 | [diff] [blame] | 15 | \refbimodindex{gdbm} |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 16 | |
| 17 | The module defines the following constant and functions: |
| 18 | |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 19 | \begin{excdesc}{error} |
| 20 | Raised on dbm-specific errors, such as I/O errors. \code{KeyError} is |
| 21 | raised for general mapping errors like specifying an incorrect key. |
| 22 | \end{excdesc} |
| 23 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 24 | \begin{funcdesc}{open}{filename, \optional{flag, \optional{mode}}} |
Guido van Rossum | 0bf8475 | 1995-07-07 22:55:57 +0000 | [diff] [blame] | 25 | Open a dbm database and return a dbm object. The \var{filename} |
| 26 | argument is the name of the database file (without the \file{.dir} or |
| 27 | \file{.pag} extensions). |
| 28 | |
| 29 | The 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 | |
| 35 | The optional \var{mode} argument is the \UNIX{} mode of the file, used |
| 36 | only when the database has to be created. It defaults to octal |
| 37 | \code{0666}. |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 38 | \end{funcdesc} |