Prevent python shelve corruption

穿精又带淫゛_ 提交于 2019-12-10 17:25:07

问题


How should I prevent corruption in a shelve file? Should the shelve be closed most of the time and then opened only when I need to read or edit a value?


回答1:


If safety of your persistent objects is of high importance in your project, using shelve is not a good idea. Neither is pickling objects and manually writing them into files.

Consider that real databases invest huge resources (brainpower and code) to be safe in case of failures. So keep your data in a real DB. The simplest would be sqlite, as it comes bundled with Python. sqlite is quite safe and has a lot of smarts in it about keeping your data in some valid state even in case of system failures (like when someone trips on your PC's power cable).



来源:https://stackoverflow.com/questions/4226580/prevent-python-shelve-corruption

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!