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?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If safety of your persistent objects is of high importance in your project, using
shelveis 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.sqliteis 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).