Problem with shelve

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bluesmanu@gmail.com

    Problem with shelve

    Hi all,

    I am trying to use the shelve module to save an object of a 'Electron'
    class I made into a file. The writing goes well but the reading goes :
    >>e=f['0']
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "shelve.py" , line 113, in __getitem__
    value = Unpickler(f).lo ad()
    AttributeError: 'module' object has no attribute 'Electron'

    any idea of what I am doing wrong?

    Thanks!
    ET
  • Paul Rudin

    #2
    Re: Problem with shelve

    bluesmanu@gmail .com writes:
    Hi all,
    >
    I am trying to use the shelve module to save an object of a 'Electron'
    class I made into a file. The writing goes well but the reading goes :
    >
    >>>e=f['0']
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "shelve.py" , line 113, in __getitem__
    value = Unpickler(f).lo ad()
    AttributeError: 'module' object has no attribute 'Electron'
    >
    any idea of what I am doing wrong?
    I'm not sure, but shelve uses pickle, and to unpickle you need to have
    the module and class definition available for import at unpickling
    time. The error message suggests that the module is there, but it no
    longer contains a definition for the Electron class.

    I could be wrong tho' :)

    Comment

    Working...