Search code examples
pythoncentos6shelve

Python shelve file extension on CentOS


When I use python shelve on Ubuntu, it saves to a file without extension. But when I use it on CentOS, 3 files appears with extensions .bac .dat and .dir. What happens here and how to make them consistent?


Solution

  • shelve uses behind the scene the dbm module, which in turns uses some native dbm bindings depending on the OS.

    Citing the docs:

    dbm is a generic interface to variants of the DBM database — dbm.gnu or dbm.ndbm. If none of these modules is installed, the slow-but-simple implementation in module dbm.dumb will be used.

    Therefore, depending on the OS you are using and what's installed on it, it might be saved in different ways.

    Shameful self-promotion: I made an alternative for shelve which you may find handy since it is platform independent: https://github.com/dagnelies/pysos