Please I need help with Shelves!!

cheve at my-deja.com cheve at my-deja.com
Thu Aug 3 15:59:37 EDT 2000


Hi

I have some problems with the shelve module working on Win95.
Please consider this code

###################################
# Begin of my code

import shelve

shelvefile = "_test2.shelve"

def make_shelve(cant):
    dato = []
    for i in range(cant):
        dato.append(1)
    d = shelve.open(shelvefile)
    d["dato"] = dato
    d.close()

def clean_shelve():
    d = shelve.open(shelvefile)
    del d["dato"]
    d.close()

def change_shelve(cant):
    d = shelve.open(shelvefile)
    dato = d["dato"]
    for i in range(cant):
        dato.append(1)
    d["dato"] = dato
    d.close()

def print_shelve():
    d = shelve.open(shelvefile)
    try:
        dato = d["dato"]
        print dato
        print len(dato)
    except :
        print "[]"
        print 0
    d.close()

# End of my code
###################################

1. If I do make_shelve(1000) I get a file with 1000 integers
with size 7168 bytes, if then I do clean_shelve() key and data
are deleted, but the file is still 7168 bytes, in fact key and
data are still there but I can´t use them.

2. If I do make_shelve(10000) I get a file with 10000 integers
with size 44032 bytes.
But if I do the next:
make_shelve(5000)
for i in range(10): change_shelve(500)
I get a file with 10000 integers too, but this time the size
is 52736 bytes.

Anybody can explainme this?
Is something bad with my code?
I tried the sync method but this does nothing.
I noted that the bsddb module is used on win95.
Thanks...

Cristian Echeverria


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list