Re: Why derivated exception can not be pickled ?

2012-09-05 Thread Mathieu Courtois
Hello, The simple example works fine using __reduce__: class MyError(Exception): def __init__(self, arg): self.arg = arg def __reduce__(self): return (MyError, (self.arg, )) -- http://mail.python.org/mailman/listinfo/python-list

Re: Why derivated exception can not be pickled ?

2012-09-05 Thread Mathieu Courtois
Thanks for your reply On Wednesday, September 5, 2012 8:02:55 AM UTC+2, Dieter Maurer wrote: > > The pickle interface is actually more complex and there are several > > ways an object can ensure picklability. For example, there is > > also a "__reduce__" method. I suppose, that "Exception" def

Re: Why derivated exception can not be pickled ?

2012-09-04 Thread Dieter Maurer
Mathieu Courtois writes: > Here is my example : > > > import cPickle > > ParentClass = object # works > ParentClass = Exception # does not > > class MyError(ParentClass): > def __init__(self, arg): > self.arg = arg > > def __getstate__(self): > print '#DBG pass in get

Re: Why derivated exception can not be pickled ?

2012-09-04 Thread Steven D'Aprano
On Tue, 04 Sep 2012 08:57:00 -0700, Mathieu Courtois wrote: > Here is my example : > > > import cPickle > > ParentClass = object # works > ParentClass = Exception # does not [...] > 1. With ParentClass=object, it works as expected. > > 2. With ParentClass=Exception, __getstate__/__setstat

Why derivated exception can not be pickled ?

2012-09-04 Thread Mathieu Courtois
Here is my example : import cPickle ParentClass = object # works ParentClass = Exception # does not class MyError(ParentClass): def __init__(self, arg): self.arg = arg def __getstate__(self): print '#DBG pass in getstate' odict = self.__dict__.copy()