Still the __new__ hell ...

Arnaud Delobelle arnodel at googlemail.com
Sun Mar 18 04:06:15 EDT 2007


On Mar 17, 11:48 pm, Paulo da Silva <psdasil... at esotericaX.ptX> wrote:
> Arnaud Delobelle escreveu:> On Mar 17, 9:31 pm, Paulo da Silva <psdasil... at esotericaX.ptX> wrote:

[snip]

> Thanks. This works exactly the way you wrote.
> Yet I am misunderstanding something. Can't pickle "see" that being
> MyDate derived from date it also has to look at variables from date?
> When do I need to do this? I am using pickle with a lot more complex
> classes without this problem.

Without the MyDate.__reduce__ method, Python uses the
datetime.date.__reduce__ method to pickle your MyDate instances, then
it uses MyDate.__new__ to unpickle them.  But your MyDate.__new__
method does not understand the format of a pickled date.  You could
also change the MyDate.__new__ method so that it does understand it,
but it wouldn't be that easy as you want it to accept a string, and
this is the format that dates are pickled in.

--
Arnaud






More information about the Python-list mailing list