Problem pickling class instance

Edward C. Jones edcjones at erols.com
Thu Jun 6 21:33:43 EDT 2002


I think the following problem may be discussed in the Python Library
Reference, section 3.14.4 but I don't understand it.

Here is the file mod.py:

     import pickle

     def Read():
         f = open('saved', 'r')
	return pickle.load(f)

     class A:
         def __init__(self):
             pass

     if __name__ == '__main__':
         a = A()
	f = open('saved', 'w')
         pickle.dump(a, f)

and the file top.py:

     import mod, pickle

     a = mod.Read()

First I run mod.py then top.py. The latter give the message:

     AttributeError: 'module' object has no attribute 'A'

Please explain the problem to me. Is there a standard work-around?

Thanks,
Ed Jones




More information about the Python-list mailing list