How can I get python to use the dumbdbm module to create a new database?

The module is shelveimplemented on top of the module anydbm. This module acts as a facade for 4 different concrete DBM implementations, and it selects the first module available when creating a new database, in the following order:

  • dbhash (deprecated but still the first choice anydbm). This is a proxy for the module bsddb, .open()reallybsddb.hashopen()

  • gdbm , the Python module for the GNU DBM library, which offers more functionality than the module dbm, can offer when used with the same library.

  • dbm , a proxy module using libraries ndbm, BSD DB and GNU DBM (selected when compiling Python).

  • dumbdbm , a pure-python implementation.

But on my system, although I have dbhash, for some reason I want it to create db only with dumbdbm.

How can i achieve this?

+5
source share
1 answer

You cannot control what the db module uses shelve.open, but there are workarounds.

It is best to create db yourself and pass its constructor Shelfmanually, instead of calling shelve.open:

db = dumbdbm.open('mydb')
shelf = shelve.Shelf(db)

The first parameter is any object that provides an dict-like interface that can store strings, which is any object *dbm.

+5
source

All Articles