shelve and ".bak .dat .dir" files

  • Thread starter Michele Petrazzo
  • Start date
M

Michele Petrazzo

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
import shelve
class XX:
def __init__(self):
self._data = shelve.open("/tmp/myfile")

# do the work

def onClose(self):
self._data.close()


Now I see that shelve create not my file, but three files that has the
name that I want (/tmp/myfile) and also the extensions: .bak .dat .dir

Of course, before say to shelve to open, I delete the previous file, and
I have all the rights to do what I want into the directory.

How solve it?

Thanks,
Michele
 
S

Sion Arrowsmith

Michele Petrazzo said:
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:
[ ... ]
Now I see that shelve create not my file, but three files that has the
name that I want (/tmp/myfile) and also the extensions: .bak .dat .dir

This is a documented behaviour of shelve:

http://docs.python.org/lib/module-shelve.html

and note "an extension may be added to the filename and more than one
file may be created". I guess this depends on what dbm shelve is
built on the documentation implies it goes through anydbm. I'm not
seeing this behaviour on my Debian 3.1 (and I fail to understand why
it is a problem).
 
M

Michele Petrazzo

Sion said:
This is a documented behaviour of shelve:

Sorry, I had read only the:
"""Open a persistent dictionary. The filename specified is the base
filename""" ... :)
I guess this depends on what dbm shelve is built on the documentation
implies it goes through anydbm. I'm not seeing this behaviour on my
Debian 3.1

In my tries, I see that if I use a "simple" script that open, use and
save the shelve data, it work without problems, but if I use shelve into
my application, I has this behaviour.

(and I fail to understand why
it is a problem).

Because:
1) I pass a name that, after, I'll pass to another program and if shelve
change the name, the latter can't read it (it doesn't exists!)
2) I can't read those files with shelve! If I try... :
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.3/shelve.py", line 231, in open
return DbfilenameShelf(filename, flag, protocol, writeback, binary)
File "/usr/lib/python2.3/shelve.py", line 212, in __init__
Shelf.__init__(self, anydbm.open(filename, flag), protocol,
writeback, binary)
File "/usr/lib/python2.3/anydbm.py", line 80, in open
raise error, "db type could not be determined"
anydbm.error: db type could not be determined


And this with all the three types.

Thanks,
Michele
 
S

Sion Arrowsmith

Michele Petrazzo said:
Sion said:
This is a documented behaviour of shelve:
[ open(filename) may create files with names based on filename + ext ]
(and I fail to understand why
it is a problem).
Because:
1) I pass a name that, after, I'll pass to another program and if shelve
change the name, the latter can't read it (it doesn't exists!)

Hmm, is there any guarantee that the filename you give to shelve.open()
to create will correspond to a single file on disk that you can hand to
another application for purposes other than opening to read with shelve?
Given that it's documented that it may create other files, it seems to
me like you'd always want the other program to look for file and file.*
anyway. Unless it's just reading:
2) I can't read those files with shelve! If I try... :
Traceback (most recent call last):
[ ... ]
anydbm.error: db type could not be determined

Did you try opening using the filename you originally gave, ie
shelve.open("test")? Of course plain open("test") will fail, but
this is opening a dbm structure based on "test" not a simple file.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top