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-gdbm.html" /> | |
13 | <link rel="prev" href="module-dl.html" /> | |
14 | <link rel="parent" href="unix.html" /> | |
15 | <link rel="next" href="module-gdbm.html" /> | |
16 | <meta name='aesop' content='information' /> | |
17 | <title>8.6 dbm -- Simple ``database'' interface</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="8.5.1 Dl Objects" | |
25 | href="dl-objects.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="8. Unix Specific Services" | |
28 | href="unix.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="8.7 gdbm " | |
31 | href="module-gdbm.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="dl-objects.html">8.5.1 Dl Objects</A> | |
46 | <b class="navlabel">Up:</b> | |
47 | <a class="sectref" rel="parent" href="unix.html">8. Unix Specific Services</A> | |
48 | <b class="navlabel">Next:</b> | |
49 | <a class="sectref" rel="next" href="module-gdbm.html">8.7 gdbm </A> | |
50 | </div> | |
51 | <hr /></div> | |
52 | </DIV> | |
53 | <!--End of Navigation Panel--> | |
54 | ||
55 | <H1><A NAME="SECTION0010600000000000000000"> | |
56 | 8.6 <tt class="module">dbm</tt> -- | |
57 | Simple ``database'' interface</A> | |
58 | </H1> | |
59 | ||
60 | <P> | |
61 | <A NAME="module-dbm"></A> | |
62 | <p class="availability">Availability: <span | |
63 | class="platform">Unix</span>.</p> | |
64 | ||
65 | <P> | |
66 | The <tt class="module">dbm</tt> module provides an interface to the <span class="Unix">Unix</span> | |
67 | (<code>n</code>)<code>dbm</code> library. Dbm objects behave like mappings | |
68 | (dictionaries), except that keys and values are always strings. | |
69 | Printing a dbm object doesn't print the keys and values, and the | |
70 | <tt class="method">items()</tt> and <tt class="method">values()</tt> methods are not supported. | |
71 | ||
72 | <P> | |
73 | This module can be used with the ``classic'' ndbm interface, the BSD | |
74 | DB compatibility interface, or the GNU GDBM compatibility interface. | |
75 | On <span class="Unix">Unix</span>, the <b class="program">configure</b> script will attempt to locate the | |
76 | appropriate header file to simplify building this module. | |
77 | ||
78 | <P> | |
79 | The module defines the following: | |
80 | ||
81 | <P> | |
82 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-2996' xml:id='l2h-2996' class="exception">error</tt></b></dt> | |
83 | <dd> | |
84 | Raised on dbm-specific errors, such as I/O errors. | |
85 | <tt class="exception">KeyError</tt> is raised for general mapping errors like | |
86 | specifying an incorrect key. | |
87 | </dd></dl> | |
88 | ||
89 | <P> | |
90 | <dl><dt><b><tt id='l2h-2997' xml:id='l2h-2997'>library</tt></b></dt> | |
91 | <dd> | |
92 | Name of the <code>ndbm</code> implementation library used. | |
93 | </dd></dl> | |
94 | ||
95 | <P> | |
96 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
97 | <td><nobr><b><tt id='l2h-2998' xml:id='l2h-2998' class="function">open</tt></b>(</nobr></td> | |
98 | <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> | |
99 | <dd> | |
100 | Open a dbm database and return a dbm object. The <var>filename</var> | |
101 | argument is the name of the database file (without the <span class="file">.dir</span> or | |
102 | <span class="file">.pag</span> extensions; note that the BSD DB implementation of the | |
103 | interface will append the extension <span class="file">.db</span> and only create one | |
104 | file). | |
105 | ||
106 | <P> | |
107 | The optional <var>flag</var> argument must be one of these values: | |
108 | ||
109 | <P> | |
110 | <div class="center"><table class="realtable"> | |
111 | <thead> | |
112 | <tr> | |
113 | <th class="center">Value</th> | |
114 | <th class="left" >Meaning</th> | |
115 | </tr> | |
116 | </thead> | |
117 | <tbody> | |
118 | <tr><td class="center" valign="baseline"><code>'r'</code></td> | |
119 | <td class="left" >Open existing database for reading only (default)</td></tr> | |
120 | <tr><td class="center" valign="baseline"><code>'w'</code></td> | |
121 | <td class="left" >Open existing database for reading and writing</td></tr> | |
122 | <tr><td class="center" valign="baseline"><code>'c'</code></td> | |
123 | <td class="left" >Open database for reading and writing, creating it if | |
124 | it doesn't exist</td></tr> | |
125 | <tr><td class="center" valign="baseline"><code>'n'</code></td> | |
126 | <td class="left" >Always create a new, empty database, open for reading | |
127 | and writing</td></tr></tbody> | |
128 | </table></div> | |
129 | ||
130 | <P> | |
131 | The optional <var>mode</var> argument is the <span class="Unix">Unix</span> mode of the file, used | |
132 | only when the database has to be created. It defaults to octal | |
133 | <code>0666</code>. | |
134 | </dl> | |
135 | ||
136 | <P> | |
137 | <div class="seealso"> | |
138 | <p class="heading">See Also:</p> | |
139 | ||
140 | <dl compact="compact" class="seemodule"> | |
141 | <dt>Module <b><tt class="module"><a href="module-anydbm.html">anydbm</a></tt>:</b> | |
142 | <dd>Generic interface to <code>dbm</code>-style databases. | |
143 | </dl> | |
144 | <dl compact="compact" class="seemodule"> | |
145 | <dt>Module <b><tt class="module"><a href="module-gdbm.html">gdbm</a></tt>:</b> | |
146 | <dd>Similar interface to the GNU GDBM library. | |
147 | </dl> | |
148 | <dl compact="compact" class="seemodule"> | |
149 | <dt>Module <b><tt class="module"><a href="module-whichdb.html">whichdb</a></tt>:</b> | |
150 | <dd>Utility module used to determine the type of an | |
151 | existing database. | |
152 | </dl> | |
153 | </div> | |
154 | ||
155 | <DIV CLASS="navigation"> | |
156 | <div class='online-navigation'> | |
157 | <p></p><hr /> | |
158 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
159 | <tr> | |
160 | <td class='online-navigation'><a rel="prev" title="8.5.1 Dl Objects" | |
161 | href="dl-objects.html"><img src='../icons/previous.png' | |
162 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
163 | <td class='online-navigation'><a rel="parent" title="8. Unix Specific Services" | |
164 | href="unix.html"><img src='../icons/up.png' | |
165 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
166 | <td class='online-navigation'><a rel="next" title="8.7 gdbm " | |
167 | href="module-gdbm.html"><img src='../icons/next.png' | |
168 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
169 | <td align="center" width="100%">Python Library Reference</td> | |
170 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
171 | href="contents.html"><img src='../icons/contents.png' | |
172 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
173 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
174 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
175 | <td class='online-navigation'><a rel="index" title="Index" | |
176 | href="genindex.html"><img src='../icons/index.png' | |
177 | border='0' height='32' alt='Index' width='32' /></A></td> | |
178 | </tr></table> | |
179 | <div class='online-navigation'> | |
180 | <b class="navlabel">Previous:</b> | |
181 | <a class="sectref" rel="prev" href="dl-objects.html">8.5.1 Dl Objects</A> | |
182 | <b class="navlabel">Up:</b> | |
183 | <a class="sectref" rel="parent" href="unix.html">8. Unix Specific Services</A> | |
184 | <b class="navlabel">Next:</b> | |
185 | <a class="sectref" rel="next" href="module-gdbm.html">8.7 gdbm </A> | |
186 | </div> | |
187 | </div> | |
188 | <hr /> | |
189 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> | |
190 | </DIV> | |
191 | <!--End of Navigation Panel--> | |
192 | <ADDRESS> | |
193 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. | |
194 | </ADDRESS> | |
195 | </BODY> | |
196 | </HTML> |