diff options
author | Guido van Rossum <guido@python.org> | 1995-02-09 17:18:10 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1995-02-09 17:18:10 (GMT) |
commit | cc6764c1ba92e947638d1c0c8fe8d312a0e3e6d4 (patch) | |
tree | def2cce7cbaf33886f5780d086bcdf093951342c /Lib/anydbm.py | |
parent | 6de668f3aa4acb93c0e54be12af4d23adb95370a (diff) | |
download | cpython-cc6764c1ba92e947638d1c0c8fe8d312a0e3e6d4.zip cpython-cc6764c1ba92e947638d1c0c8fe8d312a0e3e6d4.tar.gz cpython-cc6764c1ba92e947638d1c0c8fe8d312a0e3e6d4.tar.bz2 |
added __doc__ strings etc.
Diffstat (limited to 'Lib/anydbm.py')
-rw-r--r-- | Lib/anydbm.py | 51 |
1 files changed, 46 insertions, 5 deletions
diff --git a/Lib/anydbm.py b/Lib/anydbm.py index 49e819b..d24efe7 100644 --- a/Lib/anydbm.py +++ b/Lib/anydbm.py @@ -1,9 +1,50 @@ -"""A generic interface to all dbm clones.""" +"""A generic interface to all dbm clones. + +Instead of + + import dbm + d = dbm.open(file, 'rw', 0666) + +use + + import anydbm + d = anydbm.open(file) + +The returned object is a dbm, gdbm or (on the Mac) dbmac object, +dependent on availability of the modules (tested in this order). + +It has the following interface (key and data are strings): + + d[key] = data # store data at key (may override data at + # existing key) + data = d[key] # retrieve data at key (raise KeyError if no + # such key) + del d[key] # delete data stored at key (raises KeyError + # if no such key) + flag = d.has_key(key) # true if the key exists + list = d.keys() # return a list of all existing keys (slow!) + +Future versions may change the order in which implementations are +tested for existence, add interfaces to other db-like implementations +(e.g. BSD Hash), and (in the presence of multiple implementations) +decide which module to use based upon the extension or contents of an +existing database file. + +The open function has an optional second argument. This can be set to +'r' to open the database for reading only. Don't pas an explicit 'w' +or 'rw' to open it for writing, as the different interfaces have +different interpretation of their mode argument if it isn't 'r'. +""" try: import dbm - def open(file, mode = 'rw'): - return dbm.open(file, mode, 0666) + def open(filename, mode = 'rw'): + return dbm.open(filename, mode, 0666) except ImportError: - import dbmac - open = dbmac.open + try: + import gdbm + def open(filename, mode = 'w'): + return gdbm.open(filename, mode, 0666) + except ImportError: + import dbmac + open = dbmac.open |