shelve keeping old (unused) data around?

Skip Montanaro skip at pobox.com
Mon Sep 29 16:27:01 EDT 2003


    nospam> I'm using shelve module in python 2.3 and I found that it does a
    nospam> very odd thing, at least very unexpected to me. It seems that
    nospam> the data of a replaced or deleted key stays in filename.dat
    nospam> file.

The bits which actually get written to the disk depend on the underlying
library writing those bits.  The shelve module has no say in the matter.
All it does to create a file is ask anydbm to open it, then pickle the
values so they can be written out as strings.  Again, shelve doesn't do that
directly.  It asks the object created by anydbm to do that.  You didn't say
(perhaps you don't know) what the underlying library is on your system.  It
seems likely that the library deletes the key, but leaves the data dangling
(perhaps also marked free so it can reuse it at a later time).

Skip





More information about the Python-list mailing list