473,405 Members | 2,171 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,405 software developers and data experts.

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 7722
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Anand K Rayudu | last post by:
Hi all, I am trying to find a way to get the files recursively in a given directory, The following code is failing, can some one please suggest what could be problem here from os import...
2
by: Amir Michail | last post by:
Hi, Is there a program for editing shelve databases? Amir
3
by: Ronald W. Roberts | last post by:
I'm not sure where this routine came from, but here is the problem. On certian computers this error occurs, but it does not on others. The error is: "Undefined Function "DIR" in expression". ...
13
by: kbperry | last post by:
Hi all, Background: I need some help. I am trying to streamline a process for one of our technical writers. He is using Perforce (version control system), and is constantly changing his word...
10
by: howa | last post by:
for example, there are 10K files in the directory, given that i don't know if files name, is it possible to fetch a file randomly? thanks.
5
by: humaid | last post by:
hi guys, iam doing a project on linguistic for which i have to extract the news from a local web site,i have done so and later i have saved all the files in a directory,now i want all the...
2
by: RayOsborn | last post by:
I have some old "shelve" databases created in Python 2.2 that use the old bsddb format, whereas the version of Python 2.4 installed by my web hosting service doesn't have bsddb available at all...
2
by: hypermonkey2 | last post by:
Hi there! I am using the "shelve" module in a script to save information in between runtime sessions of the program. (its a sort of data collector, so its important to hold on to anything computed...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.