Problem with shelve

Discussion in 'Python' started by bluesmanu@gmail.com, Nov 6, 2008.

  1. Guest

    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).load()
    AttributeError: 'module' object has no attribute 'Electron'

    any idea of what I am doing wrong?

    Thanks!
    ET
    , Nov 6, 2008
    #1
    1. Advertising

  2. Paul Rudin Guest

    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).load()
    > 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' :)
    Paul Rudin, Nov 6, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rami A. Kishek

    Serious problem with Shelve

    Rami A. Kishek, Aug 17, 2003, in forum: Python
    Replies:
    6
    Views:
    494
    Rami A. Kishek
    Aug 19, 2003
  2. AK
    Replies:
    2
    Views:
    265
  3. Michael Mulcahy

    shelve problem

    Michael Mulcahy, Mar 2, 2004, in forum: Python
    Replies:
    0
    Views:
    287
    Michael Mulcahy
    Mar 2, 2004
  4. softwindow
    Replies:
    4
    Views:
    270
    Jim Segrave
    May 26, 2006
  5. Douglas Applegate

    Problem with shelve/gdbm

    Douglas Applegate, Oct 19, 2007, in forum: Python
    Replies:
    0
    Views:
    360
    Douglas Applegate
    Oct 19, 2007
Loading...

Share This Page