Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
2 | <html> | |
3 | <head> | |
4 | <link rel="STYLESHEET" href="lib.css" type='text/css' /> | |
5 | <link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" /> | |
6 | <link rel='start' href='../index.html' title='Python Documentation Index' /> | |
7 | <link rel="first" href="lib.html" title='Python Library Reference' /> | |
8 | <link rel='contents' href='contents.html' title="Contents" /> | |
9 | <link rel='index' href='genindex.html' title='Index' /> | |
10 | <link rel='last' href='about.html' title='About this document...' /> | |
11 | <link rel='help' href='about.html' title='About this document...' /> | |
12 | <link rel="next" href="module-dbhash.html" /> | |
13 | <link rel="prev" href="module-mmap.html" /> | |
14 | <link rel="parent" href="someos.html" /> | |
15 | <link rel="next" href="module-dbhash.html" /> | |
16 | <meta name='aesop' content='information' /> | |
17 | <title>7.10 anydbm -- Generic access to DBM-style databases</title> | |
18 | </head> | |
19 | <body> | |
20 | <DIV CLASS="navigation"> | |
21 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> | |
22 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
23 | <tr> | |
24 | <td class='online-navigation'><a rel="prev" title="7.9 mmap " | |
25 | href="module-mmap.html"><img src='../icons/previous.png' | |
26 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
27 | <td class='online-navigation'><a rel="parent" title="7. Optional Operating System" | |
28 | href="someos.html"><img src='../icons/up.png' | |
29 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
30 | <td class='online-navigation'><a rel="next" title="7.11 dbhash " | |
31 | href="module-dbhash.html"><img src='../icons/next.png' | |
32 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
33 | <td align="center" width="100%">Python Library Reference</td> | |
34 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
35 | href="contents.html"><img src='../icons/contents.png' | |
36 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
37 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
38 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
39 | <td class='online-navigation'><a rel="index" title="Index" | |
40 | href="genindex.html"><img src='../icons/index.png' | |
41 | border='0' height='32' alt='Index' width='32' /></A></td> | |
42 | </tr></table> | |
43 | <div class='online-navigation'> | |
44 | <b class="navlabel">Previous:</b> | |
45 | <a class="sectref" rel="prev" href="module-mmap.html">7.9 mmap </A> | |
46 | <b class="navlabel">Up:</b> | |
47 | <a class="sectref" rel="parent" href="someos.html">7. Optional Operating System</A> | |
48 | <b class="navlabel">Next:</b> | |
49 | <a class="sectref" rel="next" href="module-dbhash.html">7.11 dbhash </A> | |
50 | </div> | |
51 | <hr /></div> | |
52 | </DIV> | |
53 | <!--End of Navigation Panel--> | |
54 | ||
55 | <H1><A NAME="SECTION0091000000000000000000"> | |
56 | 7.10 <tt class="module">anydbm</tt> -- | |
57 | Generic access to DBM-style databases</A> | |
58 | </H1> | |
59 | ||
60 | <P> | |
61 | <A NAME="module-anydbm"></A> | |
62 | ||
63 | <P> | |
64 | <tt class="module">anydbm</tt> is a generic interface to variants of the DBM | |
65 | database -- <tt class="module"><a href="module-dbhash.html">dbhash</a></tt><a id='l2h-2780' xml:id='l2h-2780'></a> (requires | |
66 | <tt class="module"><a href="module-bsddb.html">bsddb</a></tt><a id='l2h-2781' xml:id='l2h-2781'></a>), | |
67 | <tt class="module"><a href="module-gdbm.html">gdbm</a></tt><a id='l2h-2782' xml:id='l2h-2782'></a>, or | |
68 | <tt class="module"><a href="module-dbm.html">dbm</a></tt><a id='l2h-2783' xml:id='l2h-2783'></a>. If none of these modules is | |
69 | installed, the slow-but-simple implementation in module | |
70 | <tt class="module"><a href="module-dumbdbm.html">dumbdbm</a></tt><a id='l2h-2784' xml:id='l2h-2784'></a> will be used. | |
71 | ||
72 | <P> | |
73 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
74 | <td><nobr><b><tt id='l2h-2778' xml:id='l2h-2778' class="function">open</tt></b>(</nobr></td> | |
75 | <td><var>filename</var><big>[</big><var>, flag</var><big>[</big><var>, mode</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt> | |
76 | <dd> | |
77 | Open the database file <var>filename</var> and return a corresponding object. | |
78 | ||
79 | <P> | |
80 | If the database file already exists, the <tt class="module"><a href="module-whichdb.html">whichdb</a></tt> module is | |
81 | used to determine its type and the appropriate module is used; if it | |
82 | does not exist, the first module listed above that can be imported is | |
83 | used. | |
84 | ||
85 | <P> | |
86 | The optional <var>flag</var> argument can be | |
87 | <code>'r'</code> to open an existing database for reading only, | |
88 | <code>'w'</code> to open an existing database for reading and writing, | |
89 | <code>'c'</code> to create the database if it doesn't exist, or | |
90 | <code>'n'</code>, which will always create a new empty database. If not | |
91 | specified, the default value is <code>'r'</code>. | |
92 | ||
93 | <P> | |
94 | The optional <var>mode</var> argument is the <span class="Unix">Unix</span> mode of the file, used | |
95 | only when the database has to be created. It defaults to octal | |
96 | <code>0666</code> (and will be modified by the prevailing umask). | |
97 | </dl> | |
98 | ||
99 | <P> | |
100 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-2779' xml:id='l2h-2779' class="exception">error</tt></b></dt> | |
101 | <dd> | |
102 | A tuple containing the exceptions that can be raised by each of the | |
103 | supported modules, with a unique exception <tt class="exception">anydbm.error</tt> as | |
104 | the first item -- the latter is used when <tt class="exception">anydbm.error</tt> is | |
105 | raised. | |
106 | </dd></dl> | |
107 | ||
108 | <P> | |
109 | The object returned by <tt class="function">open()</tt> supports most of the same | |
110 | functionality as dictionaries; keys and their corresponding values can | |
111 | be stored, retrieved, and deleted, and the <tt class="method">has_key()</tt> and | |
112 | <tt class="method">keys()</tt> methods are available. Keys and values must always be | |
113 | strings. | |
114 | ||
115 | <P> | |
116 | <div class="seealso"> | |
117 | <p class="heading">See Also:</p> | |
118 | ||
119 | <dl compact="compact" class="seemodule"> | |
120 | <dt>Module <b><tt class="module"><a href="module-dbhash.html">dbhash</a></tt>:</b> | |
121 | <dd>BSD <code>db</code> database interface. | |
122 | </dl> | |
123 | <dl compact="compact" class="seemodule"> | |
124 | <dt>Module <b><tt class="module"><a href="module-dbm.html">dbm</a></tt>:</b> | |
125 | <dd>Standard <span class="Unix">Unix</span> database interface. | |
126 | </dl> | |
127 | <dl compact="compact" class="seemodule"> | |
128 | <dt>Module <b><tt class="module"><a href="module-dumbdbm.html">dumbdbm</a></tt>:</b> | |
129 | <dd>Portable implementation of the <code>dbm</code> interface. | |
130 | </dl> | |
131 | <dl compact="compact" class="seemodule"> | |
132 | <dt>Module <b><tt class="module"><a href="module-gdbm.html">gdbm</a></tt>:</b> | |
133 | <dd>GNU database interface, based on the <code>dbm</code> interface. | |
134 | </dl> | |
135 | <dl compact="compact" class="seemodule"> | |
136 | <dt>Module <b><tt class="module"><a href="module-shelve.html">shelve</a></tt>:</b> | |
137 | <dd>General object persistence built on top of | |
138 | the Python <code>dbm</code> interface. | |
139 | </dl> | |
140 | <dl compact="compact" class="seemodule"> | |
141 | <dt>Module <b><tt class="module"><a href="module-whichdb.html">whichdb</a></tt>:</b> | |
142 | <dd>Utility module used to determine the type of an | |
143 | existing database. | |
144 | </dl> | |
145 | </div> | |
146 | ||
147 | <DIV CLASS="navigation"> | |
148 | <div class='online-navigation'> | |
149 | <p></p><hr /> | |
150 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
151 | <tr> | |
152 | <td class='online-navigation'><a rel="prev" title="7.9 mmap " | |
153 | href="module-mmap.html"><img src='../icons/previous.png' | |
154 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
155 | <td class='online-navigation'><a rel="parent" title="7. Optional Operating System" | |
156 | href="someos.html"><img src='../icons/up.png' | |
157 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
158 | <td class='online-navigation'><a rel="next" title="7.11 dbhash " | |
159 | href="module-dbhash.html"><img src='../icons/next.png' | |
160 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
161 | <td align="center" width="100%">Python Library Reference</td> | |
162 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
163 | href="contents.html"><img src='../icons/contents.png' | |
164 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
165 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
166 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
167 | <td class='online-navigation'><a rel="index" title="Index" | |
168 | href="genindex.html"><img src='../icons/index.png' | |
169 | border='0' height='32' alt='Index' width='32' /></A></td> | |
170 | </tr></table> | |
171 | <div class='online-navigation'> | |
172 | <b class="navlabel">Previous:</b> | |
173 | <a class="sectref" rel="prev" href="module-mmap.html">7.9 mmap </A> | |
174 | <b class="navlabel">Up:</b> | |
175 | <a class="sectref" rel="parent" href="someos.html">7. Optional Operating System</A> | |
176 | <b class="navlabel">Next:</b> | |
177 | <a class="sectref" rel="next" href="module-dbhash.html">7.11 dbhash </A> | |
178 | </div> | |
179 | </div> | |
180 | <hr /> | |
181 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> | |
182 | </DIV> | |
183 | <!--End of Navigation Panel--> | |
184 | <ADDRESS> | |
185 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. | |
186 | </ADDRESS> | |
187 | </BODY> | |
188 | </HTML> |