Still the __new__ hell ...

Paulo da Silva psdasilvaX at esotericaX.ptX
Sun Mar 18 13:29:48 EDT 2007


Arnaud Delobelle escreveu:
> 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
> 
> 
> 

I see now. I need to read a little further about this stuff as soon as
I get some time to do it.

Thanks Arnaud.



More information about the Python-list mailing list