[python-win32] shelve data corruption

Tim Roberts timr at probo.com
Thu Mar 6 19:23:58 CET 2008

TK Soh wrote:
> I ran into strange problem with my program that uses the shelve module
> to maintain program settings, which later turned out to be caused by
> the corrupted shelve data. It looks like the shelve module itself is
> not capable of detecting the data corruption. I wonder if there's
> anything we can do to address this issue.

What would you have it do?  If data integrity is critical for you, you 
could run a checksum or an MD5 digest of the shelve data and store that 
with the data.  That way, you can at least tell whether the shelve was 

How was the shelve damaged?  Are humans trying to edit the data by 
hand?  If so, perhaps you should write it in a more human-readable 
format.  For example, you can "pprint" a dictionary, and then restore it 
with "eval" (assuming you are prepared for security issues).  Or, you 
could use XML to save your settings.  Or, you could create your own 
format.  I often use the Windows .INI style, because it is simple to 
create and simple to parse:

    DebugLevel = 6
    DebugPrefix = "MyApplication"
    Color = 0xffddee

Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.

More information about the python-win32 mailing list