By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,190 Members | 769 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,190 IT Pros & Developers. It's quick & easy.

shelve and ".bak .dat .dir" files

P: n/a
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
Apr 6 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Michele Petrazzo <mi**************@TOGLIunipex.it> wrote:
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).

--
\S -- si***@chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/
___ | "Frankly I have no feelings towards penguins one way or the other"
\X/ | -- Arthur C. Clarke
her nu becomež se bera eadward ofdun hlęddre heafdes bęce bump bump bump
Apr 6 '06 #2

P: n/a
Sion Arrowsmith wrote:

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... :
shelve.open("test.dat")

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
Apr 6 '06 #3

P: n/a
Michele Petrazzo <mi**************@TOGLIunipex.it> wrote:
Sion Arrowsmith wrote:
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... :
shelve.open("test.dat")

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.

--
\S -- si***@chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/
___ | "Frankly I have no feelings towards penguins one way or the other"
\X/ | -- Arthur C. Clarke
her nu becomež se bera eadward ofdun hlęddre heafdes bęce bump bump bump
Apr 7 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.