Но, оказывается все не так просто. Вот пример.
Сохраняем объект:
import pickle
class O(object):
def __init__(self):
a1 = 0
o = O()
p = pickle.dumps(o, 2)
file('dump', 'wb').write(p)
import pickle
p = file('dump', 'rb').read()
o = pickle.loads(p)
print o.a1
Traceback (most recent call last):
File "C:\tmp5\\load.py", line 4, in <module>
o = pickle.loads(p)
File "C:\Python25\lib\pickle.py", line 1374, in loads
return Unpickler(file).load()
File "C:\Python25\lib\pickle.py", line 858, in load
dispatch[key](self)
File "C:\Python25\lib\pickle.py", line 1090, in load_global
klass = self.find_class(module, name)
File "C:\Python25\lib\pickle.py", line 1126, in find_class
klass = getattr(mod, name)
AttributeError: 'module' object has no attribute 'O'