~dkuhlman/python-training-materials/Materials

« back to all changes in this revision

Viewing changes to python-2.7.11-docs-html/library/dbhash.html

  • Committer: Dave Kuhlman
  • Date: 2017-04-15 16:24:56 UTC
  • Revision ID: dkuhlman@davekuhlman.org-20170415162456-iav9vozzg4iwqwv3
Updated docs

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
 
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
 
 
4
 
 
5
 
<html xmlns="http://www.w3.org/1999/xhtml">
6
 
  <head>
7
 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
8
 
    
9
 
    <title>11.10. dbhash — DBM-style interface to the BSD database library &mdash; Python 2.7.11 documentation</title>
10
 
    
11
 
    <link rel="stylesheet" href="../_static/classic.css" type="text/css" />
12
 
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
13
 
    
14
 
    <script type="text/javascript">
15
 
      var DOCUMENTATION_OPTIONS = {
16
 
        URL_ROOT:    '../',
17
 
        VERSION:     '2.7.11',
18
 
        COLLAPSE_INDEX: false,
19
 
        FILE_SUFFIX: '.html',
20
 
        HAS_SOURCE:  true
21
 
      };
22
 
    </script>
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>
39
 
 
40
 
    
41
 
 
42
 
  </head>
43
 
  <body role="document">  
44
 
    <div class="related" role="navigation" aria-label="related navigation">
45
 
      <h3>Navigation</h3>
46
 
      <ul>
47
 
        <li class="right" style="margin-right: 10px">
48
 
          <a href="../genindex.html" title="General Index"
49
 
             accesskey="I">index</a></li>
50
 
        <li class="right" >
51
 
          <a href="../py-modindex.html" title="Python Module Index"
52
 
             >modules</a> |</li>
53
 
        <li class="right" >
54
 
          <a href="bsddb.html" title="11.11. bsddb — Interface to Berkeley DB library"
55
 
             accesskey="N">next</a> |</li>
56
 
        <li class="right" >
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> &raquo;</li>
62
 
        <li>
63
 
          <span class="version_switcher_placeholder">2.7.11</span>
64
 
          <a href="../index.html">Documentation</a> &raquo;
65
 
        </li>
66
 
 
67
 
          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &raquo;</li>
68
 
          <li class="nav-item nav-item-2"><a href="persistence.html" accesskey="U">11. Data Persistence</a> &raquo;</li> 
69
 
      </ul>
70
 
    </div>    
71
 
 
72
 
    <div class="document">
73
 
      <div class="documentwrapper">
74
 
        <div class="bodywrapper">
75
 
          <div class="body" role="main">
76
 
            
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> &#8212; 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>
81
 
</div>
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>
92
 
</dd></dl>
93
 
 
94
 
<dl class="function">
95
 
<dt id="dbhash.open">
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">
101
 
<colgroup>
102
 
<col width="17%" />
103
 
<col width="83%" />
104
 
</colgroup>
105
 
<thead valign="bottom">
106
 
<tr class="row-odd"><th class="head">Value</th>
107
 
<th class="head">Meaning</th>
108
 
</tr>
109
 
</thead>
110
 
<tbody valign="top">
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
113
 
(default)</td>
114
 
</tr>
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
117
 
writing</td>
118
 
</tr>
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&#8217;t exist</td>
122
 
</tr>
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>
126
 
</tr>
127
 
</tbody>
128
 
</table>
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>
134
 
</dd></dl>
135
 
 
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>
145
 
</dl>
146
 
</div>
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>
152
 
<dl class="method">
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&#8217;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&#8217;t be sorted by the key values.  This method
158
 
returns the starting key.</p>
159
 
</dd></dl>
160
 
 
161
 
<dl class="method">
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>
166
 
</dd></dl>
167
 
 
168
 
<dl class="method">
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>
177
 
</pre></div>
178
 
</div>
179
 
</dd></dl>
180
 
 
181
 
<dl class="method">
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
186
 
traversal.</p>
187
 
</dd></dl>
188
 
 
189
 
<dl class="method">
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>
193
 
</dd></dl>
194
 
 
195
 
</div>
196
 
</div>
197
 
 
198
 
 
199
 
          </div>
200
 
        </div>
201
 
      </div>
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>
205
 
  <ul>
206
 
<li><a class="reference internal" href="#">11.10. <code class="docutils literal"><span class="pre">dbhash</span></code> &#8212; 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>
208
 
</ul>
209
 
</li>
210
 
</ul>
211
 
 
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> &#8212; GNU&#8217;s reinterpretation of dbm</a></p>
215
 
  <h4>Next topic</h4>
216
 
  <p class="topless"><a href="bsddb.html"
217
 
                        title="next chapter">11.11. <code class="docutils literal"><span class="pre">bsddb</span></code> &#8212; Interface to Berkeley DB library</a></p>
218
 
<h3>This Page</h3>
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>
223
 
</ul>
224
 
 
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" />
232
 
    </form>
233
 
    <p class="searchtip" style="font-size: 90%">
234
 
    Enter search terms or a module, class or function name.
235
 
    </p>
236
 
</div>
237
 
<script type="text/javascript">$('#searchbox').show(0);</script>
238
 
        </div>
239
 
      </div>
240
 
      <div class="clearer"></div>
241
 
    </div>  
242
 
    <div class="related" role="navigation" aria-label="related navigation">
243
 
      <h3>Navigation</h3>
244
 
      <ul>
245
 
        <li class="right" style="margin-right: 10px">
246
 
          <a href="../genindex.html" title="General Index"
247
 
             >index</a></li>
248
 
        <li class="right" >
249
 
          <a href="../py-modindex.html" title="Python Module Index"
250
 
             >modules</a> |</li>
251
 
        <li class="right" >
252
 
          <a href="bsddb.html" title="11.11. bsddb — Interface to Berkeley DB library"
253
 
             >next</a> |</li>
254
 
        <li class="right" >
255
 
          <a href="gdbm.html" title="11.9. gdbm — GNU’s reinterpretation of dbm"
256
 
             >previous</a> |</li>
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> &raquo;</li>
260
 
        <li>
261
 
          <span class="version_switcher_placeholder">2.7.11</span>
262
 
          <a href="../index.html">Documentation</a> &raquo;
263
 
        </li>
264
 
 
265
 
          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &raquo;</li>
266
 
          <li class="nav-item nav-item-2"><a href="persistence.html" >11. Data Persistence</a> &raquo;</li> 
267
 
      </ul>
268
 
    </div>  
269
 
    <div class="footer">
270
 
    &copy; <a href="../copyright.html">Copyright</a> 1990-2016, Python Software Foundation.
271
 
    <br />
272
 
    The Python Software Foundation is a non-profit corporation.
273
 
    <a href="https://www.python.org/psf/donations/">Please donate.</a>
274
 
    <br />
275
 
    Last updated on Jan 23, 2016.
276
 
    <a href="../bugs.html">Found a bug</a>?
277
 
    <br />
278
 
    Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.3.3.
279
 
    </div>
280
 
 
281
 
  </body>
282
 
</html>
 
 
b'\\ No newline at end of file'