469,275 Members | 1,871 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,275 developers. It's quick & easy.

shelve and ".bak .dat .dir" files

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
3 6371
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
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
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.

Similar topics

5 posts views Thread by Anand K Rayudu | last post: by
2 posts views Thread by Amir Michail | last post: by
3 posts views Thread by Ronald W. Roberts | last post: by
13 posts views Thread by kbperry | last post: by
10 posts views Thread by howa | last post: by
5 posts views Thread by humaid | last post: by
2 posts views Thread by RayOsborn | last post: by
2 posts views Thread by hypermonkey2 | last post: by
reply views Thread by Edwin.Madari | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.