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 | 2aefe8d | 1998-04-28 15:29:26 +0000 | [diff] [blame] | 14 | |
| 15 | If the database file already exists, the \module{whichdb} module is |
| 16 | used to determine its type and the appropriate module is used; if it |
| 17 | doesn't exist, the first module listed above that can be imported is |
| 18 | used. |
| 19 | |
Guido van Rossum | 571391b | 1997-04-03 22:41:49 +0000 | [diff] [blame] | 20 | The optional \var{flag} argument can be |
| 21 | \code{'r'} to open an existing database for reading only, |
| 22 | \code{'w'} to open an existing database for reading and writing, |
| 23 | \code{'c'} to create the database if it doesn't exist, or |
| 24 | \code{'n'}, which will always create a new empty database. If not |
| 25 | specified, the default value is \code{'r'}. |
| 26 | |
| 27 | The optional \var{mode} argument is the \UNIX{} mode of the file, used |
| 28 | 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] | 29 | \code{0666} (and will be modified by the prevailing umask). |
Guido van Rossum | 571391b | 1997-04-03 22:41:49 +0000 | [diff] [blame] | 30 | \end{funcdesc} |
| 31 | |
Fred Drake | 2764dd3 | 1998-04-07 22:08:02 +0000 | [diff] [blame] | 32 | \begin{excdesc}{error} |
Guido van Rossum | 2aefe8d | 1998-04-28 15:29:26 +0000 | [diff] [blame] | 33 | A tuple containing the exceptions that can be raised by each of the |
| 34 | supported modules, with a unique exception \exception{anydbm.error} as |
| 35 | the first item --- the latter is used when \exception{anydbm.error} is |
| 36 | raised. |
Fred Drake | 2764dd3 | 1998-04-07 22:08:02 +0000 | [diff] [blame] | 37 | \end{excdesc} |
| 38 | |
Fred Drake | ddf03bf | 1998-02-18 15:05:47 +0000 | [diff] [blame] | 39 | The object returned by \function{open()} supports most of the same |
Guido van Rossum | 571391b | 1997-04-03 22:41:49 +0000 | [diff] [blame] | 40 | functionality as dictionaries; keys and their corresponding values can |
Fred Drake | ddf03bf | 1998-02-18 15:05:47 +0000 | [diff] [blame] | 41 | be stored, retrieved, and deleted, and the \method{has_key()} and |
| 42 | \method{keys()} methods are available. Keys and values must always be |
Guido van Rossum | 51a6c90 | 1997-05-09 02:23:45 +0000 | [diff] [blame] | 43 | strings. |
Guido van Rossum | 571391b | 1997-04-03 22:41:49 +0000 | [diff] [blame] | 44 | |
Fred Drake | 2764dd3 | 1998-04-07 22:08:02 +0000 | [diff] [blame] | 45 | |
| 46 | |
| 47 | \section{Standard Module \module{dumbdbm}} |
| 48 | \label{module-dumbdbm} |
| 49 | \stmodindex{dumbdbm} |
| 50 | |
| 51 | A simple and slow database implemented entirely in Python. This |
| 52 | should only be used when no other DBM-style database is available. |
| 53 | |
| 54 | |
| 55 | \begin{funcdesc}{open}{filename\optional{, flag\optional{, mode}}} |
| 56 | Open the database file \var{filename} and return a corresponding object. |
| 57 | The optional \var{flag} argument can be |
| 58 | \code{'r'} to open an existing database for reading only, |
| 59 | \code{'w'} to open an existing database for reading and writing, |
| 60 | \code{'c'} to create the database if it doesn't exist, or |
| 61 | \code{'n'}, which will always create a new empty database. If not |
| 62 | specified, the default value is \code{'r'}. |
| 63 | |
| 64 | The optional \var{mode} argument is the \UNIX{} mode of the file, used |
| 65 | only when the database has to be created. It defaults to octal |
| 66 | \code{0666} (and will be modified by the prevailing umask). |
| 67 | \end{funcdesc} |
| 68 | |
| 69 | \begin{excdesc}{error} |
| 70 | Raised for errors not reported as \exception{KeyError} errors. |
| 71 | \end{excdesc} |