Fred Drake | 2764dd3 | 1998-04-07 22:08:02 +0000 | [diff] [blame] | 1 | \section{Standard Module \module{anydbm}} |
Fred Drake | ddf03bf | 1998-02-18 15:05:47 +0000 | [diff] [blame] | 2 | \label{module-anydbm} |
Guido van Rossum | 571391b | 1997-04-03 22:41:49 +0000 | [diff] [blame] | 3 | \stmodindex{anydbm} |
Guido van Rossum | 571391b | 1997-04-03 22:41:49 +0000 | [diff] [blame] | 4 | |
Fred Drake | ddf03bf | 1998-02-18 15:05:47 +0000 | [diff] [blame] | 5 | \module{anydbm} is a generic interface to variants of the DBM |
Fred Drake | 2764dd3 | 1998-04-07 22:08:02 +0000 | [diff] [blame] | 6 | database --- \module{dbhash}\refbimodindex{dbhash}, |
| 7 | \module{gdbm}\refbimodindex{gdbm}, or \module{dbm}\refbimodindex{dbm}. |
| 8 | If none of these modules is installed, the slow-but-simple |
| 9 | implementation in module \module{dumbdbm}\refstmodindex{dumbdbm} will |
| 10 | be used. |
Guido van Rossum | 571391b | 1997-04-03 22:41:49 +0000 | [diff] [blame] | 11 | |
Fred Drake | 2764dd3 | 1998-04-07 22:08:02 +0000 | [diff] [blame] | 12 | \begin{funcdesc}{open}{filename\optional{, flag\optional{, mode}}} |
Fred Drake | ddf03bf | 1998-02-18 15:05:47 +0000 | [diff] [blame] | 13 | Open the database file \var{filename} and return a corresponding object. |
Guido van Rossum | 571391b | 1997-04-03 22:41:49 +0000 | [diff] [blame] | 14 | The optional \var{flag} argument can be |
| 15 | \code{'r'} to open an existing database for reading only, |
| 16 | \code{'w'} to open an existing database for reading and writing, |
| 17 | \code{'c'} to create the database if it doesn't exist, or |
| 18 | \code{'n'}, which will always create a new empty database. If not |
| 19 | specified, the default value is \code{'r'}. |
| 20 | |
| 21 | The optional \var{mode} argument is the \UNIX{} mode of the file, used |
| 22 | 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] | 23 | \code{0666} (and will be modified by the prevailing umask). |
Guido van Rossum | 571391b | 1997-04-03 22:41:49 +0000 | [diff] [blame] | 24 | \end{funcdesc} |
| 25 | |
Fred Drake | 2764dd3 | 1998-04-07 22:08:02 +0000 | [diff] [blame] | 26 | \begin{excdesc}{error} |
| 27 | An alternate name for the \exception{error} exception defined by the |
| 28 | underlying database implementation. |
| 29 | \end{excdesc} |
| 30 | |
Fred Drake | ddf03bf | 1998-02-18 15:05:47 +0000 | [diff] [blame] | 31 | The object returned by \function{open()} supports most of the same |
Guido van Rossum | 571391b | 1997-04-03 22:41:49 +0000 | [diff] [blame] | 32 | functionality as dictionaries; keys and their corresponding values can |
Fred Drake | ddf03bf | 1998-02-18 15:05:47 +0000 | [diff] [blame] | 33 | be stored, retrieved, and deleted, and the \method{has_key()} and |
| 34 | \method{keys()} methods are available. Keys and values must always be |
Guido van Rossum | 51a6c90 | 1997-05-09 02:23:45 +0000 | [diff] [blame] | 35 | strings. |
Guido van Rossum | 571391b | 1997-04-03 22:41:49 +0000 | [diff] [blame] | 36 | |
Fred Drake | 2764dd3 | 1998-04-07 22:08:02 +0000 | [diff] [blame] | 37 | |
| 38 | |
| 39 | \section{Standard Module \module{dumbdbm}} |
| 40 | \label{module-dumbdbm} |
| 41 | \stmodindex{dumbdbm} |
| 42 | |
| 43 | A simple and slow database implemented entirely in Python. This |
| 44 | should only be used when no other DBM-style database is available. |
| 45 | |
| 46 | |
| 47 | \begin{funcdesc}{open}{filename\optional{, flag\optional{, mode}}} |
| 48 | Open the database file \var{filename} and return a corresponding object. |
| 49 | The optional \var{flag} argument can be |
| 50 | \code{'r'} to open an existing database for reading only, |
| 51 | \code{'w'} to open an existing database for reading and writing, |
| 52 | \code{'c'} to create the database if it doesn't exist, or |
| 53 | \code{'n'}, which will always create a new empty database. If not |
| 54 | specified, the default value is \code{'r'}. |
| 55 | |
| 56 | The optional \var{mode} argument is the \UNIX{} mode of the file, used |
| 57 | only when the database has to be created. It defaults to octal |
| 58 | \code{0666} (and will be modified by the prevailing umask). |
| 59 | \end{funcdesc} |
| 60 | |
| 61 | \begin{excdesc}{error} |
| 62 | Raised for errors not reported as \exception{KeyError} errors. |
| 63 | \end{excdesc} |