object pickling

max(01)* max at fisso.casa
Sat Jul 24 17:19:54 CEST 2004


i understand than most objects are pickable, but i cannot get a function 
pickled, or a class for that matter:

$ python
Python 2.3.3 (#2, Jan 13 2004, 00:47:05)
[GCC 3.3.3 20040110 (prerelease) (Debian)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> import pickle
 >>> def myFun():
...   return "Hi there! I am myFun..."
...
 >>> fd = open("myFile.pck", "w")
 >>> pickle.dump(myFun, fd)
 >>> fd.close()
 >>> ^D
$ python
 >>> import pickle
 >>> fd = open("myFile.pck", "r")
 >>> aFun = pickle.load(fd)
Traceback (most recent call last):
   File "<stdin>", line 1, in ?
   File "/usr/lib/python2.3/pickle.py", line 1390, in load
     return Unpickler(file).load()
   File "/usr/lib/python2.3/pickle.py", line 872, in load
     dispatch[key](self)
   File "/usr/lib/python2.3/pickle.py", line 1104, in load_global
     klass = self.find_class(module, name)
   File "/usr/lib/python2.3/pickle.py", line 1140, in find_class
     klass = getattr(mod, name)
AttributeError: 'module' object has no attribute 'myFun'
 >>>

how come?

bye

max



More information about the Python-list mailing list