ASPN ActiveState Programmer Network
  ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups | Web Services
SEARCH

Reference
ActivePython 2.5
Python Documentation
Library Reference
13. Data Persistence
13.1 pickle -- Python object serialization
13.2 cPickle -- A faster pickle
13.3 copy reg -- Register pickle support functions
13.4 shelve -- Python object persistence
13.5 marshal -- Internal Python object serialization
13.6 anydbm -- Generic access to DBM-style databases
13.7 whichdb -- Guess which DBM module created a database
13.8 dbm -- Simple ``database'' interface
13.9 gdbm -- GNU's reinterpretation of dbm
13.10 dbhash -- DBM-style interface to the BSD database library
13.11 bsddb -- Interface to Berkeley DB library
13.12 dumbdbm -- Portable DBM implementation
13.13 sqlite3 -- DB-API 2.0 interface for SQLite databases

MyASPN >> Reference >> ActivePython 2.5 >> Python Documentation >> Library Reference >> 13. Data Persistence
ActivePython 2.5 documentation

13.8 dbm -- Simple ``database'' interface

Availability: Unix.

The dbm module provides an interface to the Unix (n)dbm library. Dbm objects behave like mappings (dictionaries), except that keys and values are always strings. Printing a dbm object doesn't print the keys and values, and the items() and values() methods are not supported.

This module can be used with the ``classic'' ndbm interface, the BSD DB compatibility interface, or the GNU GDBM compatibility interface. On Unix, the configure script will attempt to locate the appropriate header file to simplify building this module.

The module defines the following:

exception error
Raised on dbm-specific errors, such as I/O errors. KeyError is raised for general mapping errors like specifying an incorrect key.

library
Name of the ndbm implementation library used.

open( filename[, flag[, mode]])
Open a dbm database and return a dbm object. The filename argument is the name of the database file (without the .dir or .pag extensions; note that the BSD DB implementation of the interface will append the extension .db and only create one file).

The optional flag argument must be one of these values:

Value Meaning
'r' Open existing database for reading only (default)
'w' Open existing database for reading and writing
'c' Open database for reading and writing, creating it if it doesn't exist
'n' Always create a new, empty database, open for reading and writing

The optional mode argument is the Unix mode of the file, used only when the database has to be created. It defaults to octal 0666.

See Also:

Module anydbm:
Generic interface to dbm-style databases.
Module gdbm:
Similar interface to the GNU GDBM library.
Module whichdb:
Utility module used to determine the type of an existing database.
See About this document... for information on suggesting changes.

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState 2004 All rights reserved