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