[Tutor] Shelve del not reducing file size
Barton David
David.Barton at nottingham.ac.uk
Fri Jul 27 10:51:54 CEST 2007
Hi,
I've hit a snag with Python's shelve module. By way of example...
_____
from shelve import DbfilenameShelf as StoreFile
import os
sf=StoreFile("mytest.db",writeback=False) # but same problem if
writeback=True
for i in range(10000):
sf[str(i)]="TESTOBJECT"
sf.sync()
print len(sf)
sf.close()
predeletesize=os.path.getsize("mytest.db")
print predeletesize
sf=StoreFile("mytest.db",writeback=False) # but same problem if
writeback=True
for i in range(5000):
del sf[str(i)]
sf.sync()
print len(sf)
sf.close()
postdeletesize=os.path.getsize("mytest.db")
print postdeletesize
_____
So why, when I run this, does predeletesize!=postdeletesize?
I gather that with most database types you have to invoke a special
command like VACUUM to perform cleanups after table deletions etc
so, since shelve uses database backends, is this related to that? Is
there a way to tell (e.g.) a DBfilenameShelf to do this? Or am I stuck
with having to delete the entire file and save it again?
Running PythonWin 2.5.1 on XP.
thanks
Dave
This message has been checked for viruses but the contents of an attachment
may still contain software viruses, which could damage your computer system:
you are advised to perform your own checks. Email communications with the
University of Nottingham may be monitored as permitted by UK legislation.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070727/20a5c4f1/attachment.html
More information about the Tutor
mailing list