blob: 70bac7997d38116f6edf99e4209d0db0c20380ac [file] [log] [blame]
Guido van Rossum51a6c901997-05-09 02:23:45 +00001\section{Standard Modules \sectcode{anydbm} and \sectcode{dumbdbm}}
Guido van Rossum571391b1997-04-03 22:41:49 +00002\stmodindex{anydbm}
3\stmodindex{dumbdbm}
4
5\code{anydbm} is a generic interface to variants of the DBM
6database--DBM, GDBM, or dbhash. If none of these modules is
Guido van Rossum51a6c901997-05-09 02:23:45 +00007installed, the slow-but-simple implementation in module \code{dumbdbm}
8will be used. Both modules provide the same interface:
Guido van Rossum571391b1997-04-03 22:41:49 +00009
Fred Drake2478f9d1997-11-30 05:38:44 +000010% not the best solution, but it's what you get for documenting both
11% at the same time.
12\renewcommand{\indexsubitem}{(in modules anydbm, dumbdbm)}
13
Guido van Rossum571391b1997-04-03 22:41:49 +000014\begin{funcdesc}{open}{filename\optional{\, flag\, mode}}
15Open the database file \var{filename} and return a corresponding object.
16The optional \var{flag} argument can be
17\code{'r'} to open an existing database for reading only,
18\code{'w'} to open an existing database for reading and writing,
19\code{'c'} to create the database if it doesn't exist, or
20\code{'n'}, which will always create a new empty database. If not
21specified, the default value is \code{'r'}.
22
23The optional \var{mode} argument is the \UNIX{} mode of the file, used
24only when the database has to be created. It defaults to octal
Guido van Rossum51a6c901997-05-09 02:23:45 +000025\code{0666} (and will be modified by the prevailing umask).
Guido van Rossum571391b1997-04-03 22:41:49 +000026\end{funcdesc}
27
Guido van Rossum51a6c901997-05-09 02:23:45 +000028The object returned by \code{open()} supports most of the same
Guido van Rossum571391b1997-04-03 22:41:49 +000029functionality as dictionaries; keys and their corresponding values can
30be stored, retrieved, and deleted, and the \code{has_key()} and
Guido van Rossum51a6c901997-05-09 02:23:45 +000031\code{keys()} methods are available. Keys and values must always be
32strings.
Guido van Rossum571391b1997-04-03 22:41:49 +000033
Guido van Rossum51a6c901997-05-09 02:23:45 +000034Both modules also export the exception \code{error}, which is raised
35for various problems. The \code{anydbm.error} exception is simply a
36different name for the \code{error} exception of the underlying
37implementation module used.