Question on metaclasses

Reinhold Birkenfeld reinhold-birkenfeld-nospam at wolke7.net
Sun Apr 24 10:40:18 EDT 2005


Steffen Glückselig wrote:
> Are wrap and get_directives somehow built-in? I couldn't find
> references to them.
> 
> I've noticed, too, that using __new__ I can manipulate the dictionary
> resulting in the behavior I intented.
> 
> I'd rather like to know: Why does it work in __new__ but not in
> __init__?
> 
> And, stimulated by your response: Why is using __new__ superior to
> __init__?

At short, __new__ is called on the class and must return the instance; that
means that the instance isn't created yet.

__init__, on the other hand, is called on the instance which is already created
at that point. So changing dct in __init__ is pointless, because the instance
(which is a class actually) is already created.

Reinhold



More information about the Python-list mailing list