blob: bba7714c1059de550037a2f2b6c7ae1515eb88ed [file] [log] [blame]
Fred Drake2764dd31998-04-07 22:08:02 +00001\section{Standard Module \module{anydbm}}
Fred Drakeddf03bf1998-02-18 15:05:47 +00002\label{module-anydbm}
Guido van Rossum571391b1997-04-03 22:41:49 +00003\stmodindex{anydbm}
Guido van Rossum571391b1997-04-03 22:41:49 +00004
Fred Drakeddf03bf1998-02-18 15:05:47 +00005\module{anydbm} is a generic interface to variants of the DBM
Fred Drake2764dd31998-04-07 22:08:02 +00006database --- \module{dbhash}\refbimodindex{dbhash},
7\module{gdbm}\refbimodindex{gdbm}, or \module{dbm}\refbimodindex{dbm}.
8If none of these modules is installed, the slow-but-simple
9implementation in module \module{dumbdbm}\refstmodindex{dumbdbm} will
10be used.
Guido van Rossum571391b1997-04-03 22:41:49 +000011
Fred Drake2764dd31998-04-07 22:08:02 +000012\begin{funcdesc}{open}{filename\optional{, flag\optional{, mode}}}
Fred Drakeddf03bf1998-02-18 15:05:47 +000013Open the database file \var{filename} and return a corresponding object.
Guido van Rossum2aefe8d1998-04-28 15:29:26 +000014
15If the database file already exists, the \module{whichdb} module is
16used to determine its type and the appropriate module is used; if it
17doesn't exist, the first module listed above that can be imported is
18used.
19
Guido van Rossum571391b1997-04-03 22:41:49 +000020The 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
25specified, the default value is \code{'r'}.
26
27The optional \var{mode} argument is the \UNIX{} mode of the file, used
28only when the database has to be created. It defaults to octal
Guido van Rossum51a6c901997-05-09 02:23:45 +000029\code{0666} (and will be modified by the prevailing umask).
Guido van Rossum571391b1997-04-03 22:41:49 +000030\end{funcdesc}
31
Fred Drake2764dd31998-04-07 22:08:02 +000032\begin{excdesc}{error}
Guido van Rossum2aefe8d1998-04-28 15:29:26 +000033A tuple containing the exceptions that can be raised by each of the
34supported modules, with a unique exception \exception{anydbm.error} as
35the first item --- the latter is used when \exception{anydbm.error} is
36raised.
Fred Drake2764dd31998-04-07 22:08:02 +000037\end{excdesc}
38
Fred Drakeddf03bf1998-02-18 15:05:47 +000039The object returned by \function{open()} supports most of the same
Guido van Rossum571391b1997-04-03 22:41:49 +000040functionality as dictionaries; keys and their corresponding values can
Fred Drakeddf03bf1998-02-18 15:05:47 +000041be stored, retrieved, and deleted, and the \method{has_key()} and
42\method{keys()} methods are available. Keys and values must always be
Guido van Rossum51a6c901997-05-09 02:23:45 +000043strings.
Guido van Rossum571391b1997-04-03 22:41:49 +000044
Fred Drake2764dd31998-04-07 22:08:02 +000045
46
47\section{Standard Module \module{dumbdbm}}
48\label{module-dumbdbm}
49\stmodindex{dumbdbm}
50
51A simple and slow database implemented entirely in Python. This
52should only be used when no other DBM-style database is available.
53
54
55\begin{funcdesc}{open}{filename\optional{, flag\optional{, mode}}}
56Open the database file \var{filename} and return a corresponding object.
57The 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
62specified, the default value is \code{'r'}.
63
64The optional \var{mode} argument is the \UNIX{} mode of the file, used
65only 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}
70Raised for errors not reported as \exception{KeyError} errors.
71\end{excdesc}