1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
<html xmlns="http://www.w3.org/1999/xhtml">
7
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
9
<title>11.10. dbhash — DBM-style interface to the BSD database library — Python 2.7.11 documentation</title>
11
<link rel="stylesheet" href="../_static/classic.css" type="text/css" />
12
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
14
<script type="text/javascript">
15
var DOCUMENTATION_OPTIONS = {
18
COLLAPSE_INDEX: false,
23
<script type="text/javascript" src="../_static/jquery.js"></script>
24
<script type="text/javascript" src="../_static/underscore.js"></script>
25
<script type="text/javascript" src="../_static/doctools.js"></script>
26
<script type="text/javascript" src="../_static/sidebar.js"></script>
27
<link rel="search" type="application/opensearchdescription+xml"
28
title="Search within Python 2.7.11 documentation"
29
href="../_static/opensearch.xml"/>
30
<link rel="author" title="About these documents" href="../about.html" />
31
<link rel="copyright" title="Copyright" href="../copyright.html" />
32
<link rel="top" title="Python 2.7.11 documentation" href="../contents.html" />
33
<link rel="up" title="11. Data Persistence" href="persistence.html" />
34
<link rel="next" title="11.11. bsddb — Interface to Berkeley DB library" href="bsddb.html" />
35
<link rel="prev" title="11.9. gdbm — GNU’s reinterpretation of dbm" href="gdbm.html" />
36
<link rel="shortcut icon" type="image/png" href="../_static/py.png" />
37
<script type="text/javascript" src="../_static/copybutton.js"></script>
38
<script type="text/javascript" src="../_static/version_switch.js"></script>
43
<body role="document">
44
<div class="related" role="navigation" aria-label="related navigation">
47
<li class="right" style="margin-right: 10px">
48
<a href="../genindex.html" title="General Index"
49
accesskey="I">index</a></li>
51
<a href="../py-modindex.html" title="Python Module Index"
54
<a href="bsddb.html" title="11.11. bsddb — Interface to Berkeley DB library"
55
accesskey="N">next</a> |</li>
57
<a href="gdbm.html" title="11.9. gdbm — GNU’s reinterpretation of dbm"
58
accesskey="P">previous</a> |</li>
59
<li><img src="../_static/py.png" alt=""
60
style="vertical-align: middle; margin-top: -1px"/></li>
61
<li><a href="https://www.python.org/">Python</a> »</li>
63
<span class="version_switcher_placeholder">2.7.11</span>
64
<a href="../index.html">Documentation</a> »
67
<li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li>
68
<li class="nav-item nav-item-2"><a href="persistence.html" accesskey="U">11. Data Persistence</a> »</li>
72
<div class="document">
73
<div class="documentwrapper">
74
<div class="bodywrapper">
75
<div class="body" role="main">
77
<div class="section" id="module-dbhash">
78
<span id="dbhash-dbm-style-interface-to-the-bsd-database-library"></span><h1>11.10. <a class="reference internal" href="#module-dbhash" title="dbhash: DBM-style interface to the BSD database library."><code class="xref py py-mod docutils literal"><span class="pre">dbhash</span></code></a> — DBM-style interface to the BSD database library<a class="headerlink" href="#module-dbhash" title="Permalink to this headline">¶</a></h1>
79
<div class="deprecated">
80
<p><span class="versionmodified">Deprecated since version 2.6: </span>The <a class="reference internal" href="#module-dbhash" title="dbhash: DBM-style interface to the BSD database library."><code class="xref py py-mod docutils literal"><span class="pre">dbhash</span></code></a> module has been removed in Python 3.</p>
82
<p id="index-0">The <a class="reference internal" href="#module-dbhash" title="dbhash: DBM-style interface to the BSD database library."><code class="xref py py-mod docutils literal"><span class="pre">dbhash</span></code></a> module provides a function to open databases using the BSD
83
<code class="docutils literal"><span class="pre">db</span></code> library. This module mirrors the interface of the other Python database
84
modules that provide access to DBM-style databases. The <a class="reference internal" href="bsddb.html#module-bsddb" title="bsddb: Interface to Berkeley DB database library"><code class="xref py py-mod docutils literal"><span class="pre">bsddb</span></code></a> module is
85
required to use <a class="reference internal" href="#module-dbhash" title="dbhash: DBM-style interface to the BSD database library."><code class="xref py py-mod docutils literal"><span class="pre">dbhash</span></code></a>.</p>
86
<p>This module provides an exception and a function:</p>
87
<dl class="exception">
88
<dt id="dbhash.error">
89
<em class="property">exception </em><code class="descclassname">dbhash.</code><code class="descname">error</code><a class="headerlink" href="#dbhash.error" title="Permalink to this definition">¶</a></dt>
90
<dd><p>Exception raised on database errors other than <a class="reference internal" href="exceptions.html#exceptions.KeyError" title="exceptions.KeyError"><code class="xref py py-exc docutils literal"><span class="pre">KeyError</span></code></a>. It is a synonym
91
for <code class="xref py py-exc docutils literal"><span class="pre">bsddb.error</span></code>.</p>
96
<code class="descclassname">dbhash.</code><code class="descname">open</code><span class="sig-paren">(</span><em>path</em><span class="optional">[</span>, <em>flag</em><span class="optional">[</span>, <em>mode</em><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#dbhash.open" title="Permalink to this definition">¶</a></dt>
97
<dd><p>Open a <code class="docutils literal"><span class="pre">db</span></code> database and return the database object. The <em>path</em> argument is
98
the name of the database file.</p>
99
<p>The <em>flag</em> argument can be:</p>
100
<table border="1" class="docutils">
105
<thead valign="bottom">
106
<tr class="row-odd"><th class="head">Value</th>
107
<th class="head">Meaning</th>
111
<tr class="row-even"><td><code class="docutils literal"><span class="pre">'r'</span></code></td>
112
<td>Open existing database for reading only
115
<tr class="row-odd"><td><code class="docutils literal"><span class="pre">'w'</span></code></td>
116
<td>Open existing database for reading and
119
<tr class="row-even"><td><code class="docutils literal"><span class="pre">'c'</span></code></td>
120
<td>Open database for reading and writing,
121
creating it if it doesn’t exist</td>
123
<tr class="row-odd"><td><code class="docutils literal"><span class="pre">'n'</span></code></td>
124
<td>Always create a new, empty database, open
125
for reading and writing</td>
129
<p>For platforms on which the BSD <code class="docutils literal"><span class="pre">db</span></code> library supports locking, an <code class="docutils literal"><span class="pre">'l'</span></code>
130
can be appended to indicate that locking should be used.</p>
131
<p>The optional <em>mode</em> parameter is used to indicate the Unix permission bits that
132
should be set if a new database must be created; this will be masked by the
133
current umask value for the process.</p>
136
<div class="admonition seealso">
137
<p class="first admonition-title">See also</p>
138
<dl class="last docutils">
139
<dt>Module <a class="reference internal" href="anydbm.html#module-anydbm" title="anydbm: Generic interface to DBM-style database modules."><code class="xref py py-mod docutils literal"><span class="pre">anydbm</span></code></a></dt>
140
<dd>Generic interface to <code class="docutils literal"><span class="pre">dbm</span></code>-style databases.</dd>
141
<dt>Module <a class="reference internal" href="bsddb.html#module-bsddb" title="bsddb: Interface to Berkeley DB database library"><code class="xref py py-mod docutils literal"><span class="pre">bsddb</span></code></a></dt>
142
<dd>Lower-level interface to the BSD <code class="docutils literal"><span class="pre">db</span></code> library.</dd>
143
<dt>Module <a class="reference internal" href="whichdb.html#module-whichdb" title="whichdb: Guess which DBM-style module created a given database."><code class="xref py py-mod docutils literal"><span class="pre">whichdb</span></code></a></dt>
144
<dd>Utility module used to determine the type of an existing database.</dd>
147
<div class="section" id="database-objects">
148
<span id="dbhash-objects"></span><h2>11.10.1. Database Objects<a class="headerlink" href="#database-objects" title="Permalink to this headline">¶</a></h2>
149
<p>The database objects returned by <a class="reference internal" href="#dbhash.open" title="dbhash.open"><code class="xref py py-func docutils literal"><span class="pre">open()</span></code></a> provide the methods common to all
150
the DBM-style databases and mapping objects. The following methods are
151
available in addition to the standard methods.</p>
153
<dt id="dbhash.dbhash.first">
154
<code class="descclassname">dbhash.</code><code class="descname">first</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#dbhash.dbhash.first" title="Permalink to this definition">¶</a></dt>
155
<dd><p>It’s possible to loop over every key/value pair in the database using this
156
method and the <code class="xref py py-meth docutils literal"><span class="pre">next()</span></code> method. The traversal is ordered by the databases
157
internal hash values, and won’t be sorted by the key values. This method
158
returns the starting key.</p>
162
<dt id="dbhash.dbhash.last">
163
<code class="descclassname">dbhash.</code><code class="descname">last</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#dbhash.dbhash.last" title="Permalink to this definition">¶</a></dt>
164
<dd><p>Return the last key/value pair in a database traversal. This may be used to
165
begin a reverse-order traversal; see <a class="reference internal" href="#dbhash.dbhash.previous" title="dbhash.dbhash.previous"><code class="xref py py-meth docutils literal"><span class="pre">previous()</span></code></a>.</p>
169
<dt id="dbhash.dbhash.next">
170
<code class="descclassname">dbhash.</code><code class="descname">next</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#dbhash.dbhash.next" title="Permalink to this definition">¶</a></dt>
171
<dd><p>Returns the key next key/value pair in a database traversal. The following code
172
prints every key in the database <code class="docutils literal"><span class="pre">db</span></code>, without having to create a list in
173
memory that contains them all:</p>
174
<div class="highlight-python"><div class="highlight"><pre><span class="k">print</span> <span class="n">db</span><span class="o">.</span><span class="n">first</span><span class="p">()</span>
175
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">xrange</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">db</span><span class="p">)):</span>
176
<span class="k">print</span> <span class="n">db</span><span class="o">.</span><span class="n">next</span><span class="p">()</span>
182
<dt id="dbhash.dbhash.previous">
183
<code class="descclassname">dbhash.</code><code class="descname">previous</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#dbhash.dbhash.previous" title="Permalink to this definition">¶</a></dt>
184
<dd><p>Returns the previous key/value pair in a forward-traversal of the database. In
185
conjunction with <a class="reference internal" href="#dbhash.dbhash.last" title="dbhash.dbhash.last"><code class="xref py py-meth docutils literal"><span class="pre">last()</span></code></a>, this may be used to implement a reverse-order
190
<dt id="dbhash.dbhash.sync">
191
<code class="descclassname">dbhash.</code><code class="descname">sync</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#dbhash.dbhash.sync" title="Permalink to this definition">¶</a></dt>
192
<dd><p>This method forces any unwritten data to be written to the disk.</p>
202
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
203
<div class="sphinxsidebarwrapper">
204
<h3><a href="../contents.html">Table Of Contents</a></h3>
206
<li><a class="reference internal" href="#">11.10. <code class="docutils literal"><span class="pre">dbhash</span></code> — DBM-style interface to the BSD database library</a><ul>
207
<li><a class="reference internal" href="#database-objects">11.10.1. Database Objects</a></li>
212
<h4>Previous topic</h4>
213
<p class="topless"><a href="gdbm.html"
214
title="previous chapter">11.9. <code class="docutils literal"><span class="pre">gdbm</span></code> — GNU’s reinterpretation of dbm</a></p>
216
<p class="topless"><a href="bsddb.html"
217
title="next chapter">11.11. <code class="docutils literal"><span class="pre">bsddb</span></code> — Interface to Berkeley DB library</a></p>
219
<ul class="this-page-menu">
220
<li><a href="../bugs.html">Report a Bug</a></li>
221
<li><a href="../_sources/library/dbhash.txt"
222
rel="nofollow">Show Source</a></li>
225
<div id="searchbox" style="display: none" role="search">
226
<h3>Quick search</h3>
227
<form class="search" action="../search.html" method="get">
228
<input type="text" name="q" />
229
<input type="submit" value="Go" />
230
<input type="hidden" name="check_keywords" value="yes" />
231
<input type="hidden" name="area" value="default" />
233
<p class="searchtip" style="font-size: 90%">
234
Enter search terms or a module, class or function name.
237
<script type="text/javascript">$('#searchbox').show(0);</script>
240
<div class="clearer"></div>
242
<div class="related" role="navigation" aria-label="related navigation">
245
<li class="right" style="margin-right: 10px">
246
<a href="../genindex.html" title="General Index"
249
<a href="../py-modindex.html" title="Python Module Index"
252
<a href="bsddb.html" title="11.11. bsddb — Interface to Berkeley DB library"
255
<a href="gdbm.html" title="11.9. gdbm — GNU’s reinterpretation of dbm"
257
<li><img src="../_static/py.png" alt=""
258
style="vertical-align: middle; margin-top: -1px"/></li>
259
<li><a href="https://www.python.org/">Python</a> »</li>
261
<span class="version_switcher_placeholder">2.7.11</span>
262
<a href="../index.html">Documentation</a> »
265
<li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li>
266
<li class="nav-item nav-item-2"><a href="persistence.html" >11. Data Persistence</a> »</li>
270
© <a href="../copyright.html">Copyright</a> 1990-2016, Python Software Foundation.
272
The Python Software Foundation is a non-profit corporation.
273
<a href="https://www.python.org/psf/donations/">Please donate.</a>
275
Last updated on Jan 23, 2016.
276
<a href="../bugs.html">Found a bug</a>?
278
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.3.3.
b'\\ No newline at end of file'