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