Problem with shelve

B

bluesmanu

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 :
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
 
P

Paul Rudin

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 :
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' :)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top