Comment 4 for bug 363115

Revision history for this message
reckoner (reckoner) wrote : Re: [Bug 363115] Re: cPickle works in standard interpreter, but not in IPython

If you get the class using the %run magic instead of importing, you DO
get the pickle failure. I don't know if doing %run is the same as
defining a class interactively, though.

Any guidance appreciated.

thanks.

On Sat, Jul 18, 2009 at 1:11 PM, Ville M. Vainio<email address hidden> wrote:
> On Sat, Jul 18, 2009 at 10:36 PM, Matt
> Hickford<email address hidden> wrote:
>> I have problem that neither pickle nor cPickle work in ipython (but work
>> in python proper).
>>
>> In my case pickle.dump works but pickle.
>
> I think you'll note that pickle works when the class of the pickleable
> object is not declared interactively, but rather imported from module.
>
> --
> Ville M. Vainio
> http://tinyurl.com/vainio
>
> --
> cPickle works in standard interpreter, but not in IPython
> https://bugs.launchpad.net/bugs/363115
> You received this bug notification because you are a direct subscriber
> of the bug.
>
> Status in IPython - Enhanced Interactive Python: Confirmed
>
> Bug description:
>
> for example:
>
> In IPython:
>
>
>>> class Mylist(list):
>       def __init__(self,x=[]):
>           list.__init__(self,x)
>
>>> from cPickle import dumps
>>> w=Mylist([1,2,3])
>>> dumps(w)
>
> PicklingError: Can't pickle <class '__main__.Mylist'>: attribute
> lookup __main__.Mylist failed
>
> However, using the standard Python interpreter:
>
> Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)] on
> win32
> Type "help", "copyright", "credits" or "license" for more information.
>>>> from cPickle import dumps
>>>> class Mylist(list):
> ...         def __init__(self,x=[]):
> ...             list.__init__(self,x)
> ...
>>>> w=Mylist([1,2,3])
>>>> dumps(w)
> 'ccopy_reg\n_reconstructor\np1\n(c__main__\nMylist\np2\nc__builtin__\nlist\np3\n
> (lp4\nI1\naI2\naI3\natRp5\n.'
>>>>
>