Guido van Rossum | 51a6c90 | 1997-05-09 02:23:45 +0000 | [diff] [blame] | 1 | \section{Standard Modules \sectcode{anydbm} and \sectcode{dumbdbm}} |
Guido van Rossum | 571391b | 1997-04-03 22:41:49 +0000 | [diff] [blame] | 2 | \stmodindex{anydbm} |
| 3 | \stmodindex{dumbdbm} |
| 4 | |
| 5 | \code{anydbm} is a generic interface to variants of the DBM |
| 6 | database--DBM, GDBM, or dbhash. If none of these modules is |
Guido van Rossum | 51a6c90 | 1997-05-09 02:23:45 +0000 | [diff] [blame] | 7 | installed, the slow-but-simple implementation in module \code{dumbdbm} |
| 8 | will be used. Both modules provide the same interface: |
Guido van Rossum | 571391b | 1997-04-03 22:41:49 +0000 | [diff] [blame] | 9 | |
| 10 | \begin{funcdesc}{open}{filename\optional{\, flag\, mode}} |
| 11 | Open the database file \var{filename} and return a corresponding object. |
| 12 | The optional \var{flag} argument can be |
| 13 | \code{'r'} to open an existing database for reading only, |
| 14 | \code{'w'} to open an existing database for reading and writing, |
| 15 | \code{'c'} to create the database if it doesn't exist, or |
| 16 | \code{'n'}, which will always create a new empty database. If not |
| 17 | specified, the default value is \code{'r'}. |
| 18 | |
| 19 | The optional \var{mode} argument is the \UNIX{} mode of the file, used |
| 20 | only when the database has to be created. It defaults to octal |
Guido van Rossum | 51a6c90 | 1997-05-09 02:23:45 +0000 | [diff] [blame] | 21 | \code{0666} (and will be modified by the prevailing umask). |
Guido van Rossum | 571391b | 1997-04-03 22:41:49 +0000 | [diff] [blame] | 22 | \end{funcdesc} |
| 23 | |
Guido van Rossum | 51a6c90 | 1997-05-09 02:23:45 +0000 | [diff] [blame] | 24 | The object returned by \code{open()} supports most of the same |
Guido van Rossum | 571391b | 1997-04-03 22:41:49 +0000 | [diff] [blame] | 25 | functionality as dictionaries; keys and their corresponding values can |
| 26 | be stored, retrieved, and deleted, and the \code{has_key()} and |
Guido van Rossum | 51a6c90 | 1997-05-09 02:23:45 +0000 | [diff] [blame] | 27 | \code{keys()} methods are available. Keys and values must always be |
| 28 | strings. |
Guido van Rossum | 571391b | 1997-04-03 22:41:49 +0000 | [diff] [blame] | 29 | |
Guido van Rossum | 51a6c90 | 1997-05-09 02:23:45 +0000 | [diff] [blame] | 30 | Both modules also export the exception \code{error}, which is raised |
| 31 | for various problems. The \code{anydbm.error} exception is simply a |
| 32 | different name for the \code{error} exception of the underlying |
| 33 | implementation module used. |