object pickling

M

max(01)*

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..... return "Hi there! I am myFun..."
....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
 
M

max(01)*

max(01)* said:
i understand than most objects are pickable, but i cannot get a function
pickled

also i would like to know: why in the world would anyone want to pickle
a builtin function, as the documentation says it's possible?

m
 
P

paolo veronelli

also i would like to know: why in the world would anyone want to pickle
a builtin function, as the documentation says it's possible?

m
actually docs explain well that you can't ,at least that way.

from python2.3/lib/node64.html

Note that functions (built-in and user-defined) are pickled by ``fully
qualified'' name reference, not by value. This means that only the
function name is pickled, along with the name of module the function is
defined in. Neither the function's code, nor any of its function
attributes are pickled. Thus the defining module must be importable in the
unpickling environment, and the module must contain the named object,
otherwise an exception will be raised.

follow there an explanation of this choice

ciao Paolino
 

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,780
Messages
2,569,609
Members
45,253
Latest member
BlytheFant

Latest Threads

Top