"shelve" save object

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

    #1

    "shelve" save object

    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 ).
    In any case, I shelve into a file "test.txt". I notice that when i try
    running the program on a different computer (by either emailing or
    transfering the file "test.txt" via USB key), the program is unable to
    load the shelve file.
    What can I do to fix this? It would be a great shame to see that after
    collecting all this information and shelving it that I cannot move to
    another computer or share the information through the "save.txt" file.

    Thanks in advance!
    Jon
  • John Machin

    #2
    Re: "shelve&qu ot; save object

    On Aug 10, 5:32 am, hypermonkey2 <jonmo...@gmail .comwrote:
    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 ).
    In any case, I shelve into a file "test.txt". I notice that when i try
    running the program on a different computer (by either emailing or
    transfering the file "test.txt" via USB key), the program is unable to
    load the shelve file.
    What can I do to fix this? It would be a great shame to see that after
    collecting all this information and shelving it that I cannot move to
    another computer or share the information through the "save.txt" file.
    For a start, you could consider telling us what "unable to load the
    shelve file" means ... please copy any error message, exception
    information and traceback and paste it into your response. Showing the
    code that deals with the shelf file would also be useful; we don't
    want to guess what your shelve.open args are.

    .... "on a different computer": How many different computers? How many
    times? To check the possibility that the file was mangled in transit
    between computers, have you compared the filesize and md5 checksum
    before and after transport?

    When asking questions like this, it's a very good idea to state what
    computer platform, what version of what OS, and what version of
    Python. In your case, you need to report this info for both the
    creating computer and the unable-to-load computers(s).

    Try this on both the creating computer and the unable-to-load
    computers(s), at the Python interactive prompt:
    >>import whichdb
    >>whichdb.which db('test.txt')
    and report the results.

    Also consider changing the name from "test.txt" to something
    meaningful -- a file with a ".txt" extension is just begging silly
    software and silly humans to treat it as a text file and mangle it.

    HTH,
    John

    Comment

    • alex23

      #3
      Re: &quot;shelve&qu ot; save object

      hypermonkey2 wrote:
      In any case, I shelve into a file "test.txt". I notice that when i try
      running the program on a different computer (by either emailing or
      transfering the file "test.txt" via USB key), the program is unable to
      load the shelve file.
      You might find the 3rd party module 'shove' is more suitable for your
      needs here.

      http://pypi.python.org/pypi/shove

      It provides a lot more backend support than shelve, of particular
      interest to you would be filesystem (& maybe sqlite).
      >>from shove import Shove
      >>fsdb = Shove('file://persistent.db')
      >>fsdb['key1'] = 'value1'
      >>fsdb.close( )
      In this example, using the file protocol will produce a
      'persistent.db' folder with the key/value pairs stored within it as
      files. This should be cross platform enough for your needs.

      Comment

      Working...