blob: 592fd210ede9bbf06173895d37ad7408b576de53 [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 Rossum571391b1997-04-03 22:41:49 +000014The 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
19specified, the default value is \code{'r'}.
20
21The optional \var{mode} argument is the \UNIX{} mode of the file, used
22only when the database has to be created. It defaults to octal
Guido van Rossum51a6c901997-05-09 02:23:45 +000023\code{0666} (and will be modified by the prevailing umask).
Guido van Rossum571391b1997-04-03 22:41:49 +000024\end{funcdesc}
25
Fred Drake2764dd31998-04-07 22:08:02 +000026\begin{excdesc}{error}
27An alternate name for the \exception{error} exception defined by the
28underlying database implementation.
29\end{excdesc}
30
Fred Drakeddf03bf1998-02-18 15:05:47 +000031The object returned by \function{open()} supports most of the same
Guido van Rossum571391b1997-04-03 22:41:49 +000032functionality as dictionaries; keys and their corresponding values can
Fred Drakeddf03bf1998-02-18 15:05:47 +000033be stored, retrieved, and deleted, and the \method{has_key()} and
34\method{keys()} methods are available. Keys and values must always be
Guido van Rossum51a6c901997-05-09 02:23:45 +000035strings.
Guido van Rossum571391b1997-04-03 22:41:49 +000036
Fred Drake2764dd31998-04-07 22:08:02 +000037
38
39\section{Standard Module \module{dumbdbm}}
40\label{module-dumbdbm}
41\stmodindex{dumbdbm}
42
43A simple and slow database implemented entirely in Python. This
44should only be used when no other DBM-style database is available.
45
46
47\begin{funcdesc}{open}{filename\optional{, flag\optional{, mode}}}
48Open the database file \var{filename} and return a corresponding object.
49The 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
54specified, the default value is \code{'r'}.
55
56The optional \var{mode} argument is the \UNIX{} mode of the file, used
57only 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}
62Raised for errors not reported as \exception{KeyError} errors.
63\end{excdesc}