shelve and ".bak .dat .dir" files

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Michele Petrazzo

    #1

    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.clos e()


    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
  • Sion Arrowsmith

    #2
    Re: shelve and ".bak .dat .dir" files

    Michele Petrazzo <michele.petraz zo@TOGLIunipex. it> wrote:[color=blue]
    >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[/color]

    This is a documented behaviour of shelve:

    Source code: Lib/shelve.py A “shelf” is a persistent, dictionary-like object. The difference with “dbm” databases is that the values (not the keys!) in a shelf can be essentially arbitrary Python o...


    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 -- siona@chiark.gr eenend.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

    Comment

    • Michele Petrazzo

      #3
      Re: shelve and &quot;.bak .dat .dir&quot; files

      Sion Arrowsmith wrote:[color=blue]
      >
      > This is a documented behaviour of shelve:[/color]

      Sorry, I had read only the:
      """Open a persistent dictionary. The filename specified is the base
      filename""" ... :)
      [color=blue]
      > 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[/color]

      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[color=blue]
      > it is a problem).
      >[/color]

      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... :
      [color=blue][color=green][color=darkred]
      >>> shelve.open("te st.dat")[/color][/color][/color]
      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(fil ename, 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

      Comment

      • Sion Arrowsmith

        #4
        Re: shelve and &quot;.bak .dat .dir&quot; files

        Michele Petrazzo <michele.petraz zo@TOGLIunipex. it> wrote:[color=blue]
        >Sion Arrowsmith wrote:[color=green]
        >> This is a documented behaviour of shelve:[/color]
        > [ open(filename) may create files with names based on filename + ext ]
        >(and I fail to understand why[color=green]
        >> it is a problem).[/color]
        >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!)[/color]

        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:
        [color=blue]
        >2) I can't read those files with shelve! If I try... :
        >[color=green][color=darkred]
        >>>> shelve.open("te st.dat")[/color][/color]
        >Traceback (most recent call last):
        > [ ... ]
        >anydbm.error : db type could not be determined[/color]

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

        --
        \S -- siona@chiark.gr eenend.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

        Comment

        Working...