[IPython-user] can't pickle interactively defined function

Robin robince@gmail....
Sat Oct 25 17:12:15 CDT 2008


Hi,

After having some trouble with the processing module in ipython I
think the problem is related to functions defined interactively in
ipython (or through an %edit) being unpickle-able. Since this has
nothing to do really with the processing module I thought I'd start a
new thread. The simplest way to demonstrate the problem is below:

In [1]: from pooltest import f
In [2]: f??
Type:           function
Base Class:     <type 'function'>
String Form:    <function f at 0x2532370>
Namespace:      Interactive
File:           /Users/robince/bzr/handy/pooltest.py
Definition:     f(x)
Source:
def f(x):
    return x*x
In [3]: from cPickle import dumps
In [4]: dumps(f)
Out[4]: 'cpooltest\nf\np1\n.'
In [5]: def f(x):
   ...:     return x*x
   ...:
In [6]: f??
Type:           function
Base Class:     <type 'function'>
String Form:    <function f at 0x25323b0>
Namespace:      Interactive
File:           /Users/robince/bzr/handy/<ipython console>
Definition:     f(x)
Docstring [source file open failed]:
    <no docstring>

In [7]: dumps(f)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)

/Users/robince/bzr/handy/<ipython console> in <module>()

/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/copy_reg.pyc
in _reduce_ex(self, proto)
     67     else:
     68         if base is self.__class__:
---> 69             raise TypeError, "can't pickle %s objects" % base.__name__
     70         state = base(self)
     71     args = (self.__class__, base, state)

TypeError: can't pickle function objects

Is this a bug?

Robin


More information about the IPython-user mailing list