Python 在 CentOS 上搁置文件扩展名

Python shelve file extension on CentOS

当我在 Ubuntu 上使用 python 搁置时,它会保存到一个没有扩展名的文件中。但是当我在 CentOS 上使用它时,会出现 3 个扩展名为 .bac .dat 和 .dir 的文件。这里发生了什么以及如何使它们保持一致?

shelve 在后台使用 dbm 模块,后者又根据 OS.

使用一些原生 dbm 绑定

引用文档:

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.

因此,根据您使用的 OS 和上面安装的内容,它可能会以不同的方式保存。

可耻的自我推销:我为 shelve 做了一个替代方案,你可能会发现它很方便,因为它与平台无关:https://github.com/dagnelies/pysos