The Berkeley DB Module
Python comes with the
bsddb module, which wraps the Berkeley Database
library (also known as BSD DB) if that library is installed on your
system and your Python installation is built to support it. With the
BSD DB library, you can create hash, binary tree, or record-based
files that generally behave like dictionaries. On Windows, Python
includes a port of the BSD DB library, thus ensuring that module
bsddb is always usable. To download BSD DB
sources, binaries for other platforms, and detailed documentation on
BSD DB, see http://www.sleepycat.com. Module
bsddb supplies three factory functions,
btopen, hashopen, and
rnopen.
Reference Section
Reference Section
Reference Section
Reference Section
Reference Section
Reference Section
Reference Section
Reference Section
Reference Section
Examples of Berkeley DB Use
The Berkeley DB is suited to tasks similar to those for which
DBM-like files are appropriate. Indeed, anydbm
uses dbhash, the DBM-like interface to the
Berkeley DB, to create new DBM-like files. In addition, the Berkeley
DB can also use other file formats when you use module
bsddb explicitly. The binary tree format, while
not quite as fast as the hashed format when all you need is keyed
access, is excellent when you also need to access keys in
alphabetical order.
The following example handles the same task as the DBM example shown
earlier, but uses bsddb rather than
anydbm:
import fileinput, os, bsddb wordPos = { } sep = os.pathsep for line in fileinput.input( ...Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access