문제

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?

도움이 되었습니까?

해결책

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).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top