How can I force python to use dumbdbm module to create a new database?
database, python, shelve, unix
Solution
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.
Problem
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?