The anydbm Module

The anydbm module provides a unified interface to the simple database drivers supported by Python.

The first time it is imported, the anydbm module looks for a suitable database driver, testing for dbhash, gdbm, dbm, or dumbdbm, in that order. If no such module is found, it raises an ImportError exception.

In Example 10-1, the open function is used to open or create a database, using the chosen database handler.

Example 10-1. Using the anydbm Module

File: anydbm-example-1.py

import anydbm

db = anydbm.open("database", "c")
db["1"] = "one"
db["2"] = "two"
db["3"] = "three"
db.close()

db = anydbm.open("database", "r")
for key in db.keys():
 print repr(key), repr(db[key])

'2' 'two'
'3' 'three'
'1' 'one'

Core Modules

More Standard Modules

Threads and Processes

Data Representation

File Formats

Mail and News Message Processing

Network Protocols

Internationalization

Multimedia Modules

Data Storage

Tools and Utilities

Platform-Specific Modules

Implementation Support Modules

Other Modules

show all menu





Python Standard Library
Python Standard Library (Nutshell Handbooks) with
ISBN: 0596000960
EAN: 2147483647
Year: 2000
Pages: 252
Authors: Fredrik Lundh
Similar book on Amazon

Flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net