473,382 Members | 1,545 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

shelve keeping old (unused) data around?

AK

Hello,

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

Example:
d = [1]*1000
from shelve import *
s = open('test')
s['test'] = d
s.close()
test.dat is 4100 bytes
d = 1
s = open('test')
s['test'] = d
s.close()


test.dat is still 4100 bytes

If I do del s['test'], it stays the same.

Jul 18 '05 #1
2 1433

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

Jul 18 '05 #2
AK
In article <ma**********************************@python.org >, Skip
Montanaro wrote:

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
Okay, as long as it's not a bug.. For the record, it seems like it's
bsddb on this side. Thanks, Skip!

-AK


Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Rami A. Kishek | last post by:
Hi - this mysterious behavior with shelve is just about to kill me. I hope someone here can shed some light. First of all, I have this piece of code which uses shelve to save instances of some...
1
by: Kris Caselden | last post by:
Python's docs say that Shelve uses Pickle to serialize its data. However, I've noticed that Pickle can maintain internal links, while Shelve cannot. For instance: >>> d =...
1
by: Eric Wichterich | last post by:
Hello Pythonistas, I use Python shelves to store results from MySQL-Queries (using Python for web scripting). One script searches the MySQL-database and stores the result, the next script reads...
4
by: Terry Hancock | last post by:
I only just recently had a look at the shelve module, and it looks pretty handy, my only question being, what if I really want two shelves? Must I use two files? Also, it seems strange that...
5
by: Brad Tobin | last post by:
On a production database, there is a 2GB database, when I run sp_spaceused it indicates a very high quanity of unused space. The database has been shrunk & free space sent to the OS. Why is this...
3
by: Michele Petrazzo | last post by:
Hi, I'm trying a script on a debian 3.1 that has problems on shelve library. The same script work well on a fedora 2 and I don't know why it create this problem on debian: #extract from my code...
13
by: 7stud | last post by:
test1.py: -------------------- import shelve s = shelve.open("/Users/me/2testing/dir1/aaa.txt") s = "red" s.close() --------output:------ $ python test1.py
1
by: Joshua J. Kugler | last post by:
I am using shelve to store some data since it is probably the best solution to my "data formats, number of columns, etc can change at any time" problem. However, I seem to be dealing with bloat. ...
0
by: Edwin.Madari | last post by:
since choice of dbm used by shelve http://docs.python.org/lib/node327.html depends on os, and whats available on it, shevle files saved on one os, most likely do not work on another os, sometimes on...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.