shelve and ".bak .dat .dir" files

Sion Arrowsmith siona at chiark.greenend.org.uk
Fri Apr 7 10:40:08 EDT 2006


Michele Petrazzo  <michele.petrazzo at 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 -- siona at 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



More information about the Python-list mailing list