anydbm biasing

E

Eric S. Johansson

I have a preference for gdbm when building DBM based dictionaries but
have found I cannot count on it being there all the time. Therefore, I
have created this little tidbit which you call before opening your
anydbm database to bias the preference towards gdbm instead of dbhash:

# bias DBM towards gdbm if at all possible.
def bias_anydbm():
"""bias anydbm to gdbm"""

try:
_mod = __import__("gdbm")
except ImportError:
pass
else:
# and other words, if you can import gdbm, make it the default
anydbm._defaultmod = _mod


usage:
bias_anydbm()
open_DBM = anydbm.open(DBM_path, 'c')

if you have gdbm enabled, it will use that otherwise it will default to
the search list in anydbm. obviously, this can be used to bias anydbm
to meet your own preferences

---eric
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,266
Messages
2,571,073
Members
48,772
Latest member
Backspace Studios

Latest Threads

Top