Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

The shelve module is implemented on top of the anydbm module. This module acts as a façade for 4 different specific DBM implementations, and it will pick the first module available when creating a new database, in the following order:

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

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

  • dbm, a proxy module using either the ndbm, BSD DB and GNU DBM libraries (chosen when Python is compiled).

  • dumbdbm, a pure-python implementation.

But in my system although I have dbhash for some reason I want it to create the db just with the dumbdbm.

How can I achieve that?

like image 345
Ali_IT Avatar asked Apr 26 '13 22:04

Ali_IT


1 Answers

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

The best is usually to create the db yourself and pass it to the Shelf constructor manually, instead of calling shelve.open:

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

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

like image 81
abarnert Avatar answered Oct 16 '22 19:10

abarnert