Can __new__ prevent __init__ from being called?

Colin J. Williams cjw at sympatico.ca
Wed Feb 16 13:36:31 EST 2005


Felix Wiemann wrote:
> Steven Bethard wrote:
> 
> 
>>Felix Wiemann wrote:
>>
>>
>>>How can I prevent __init__ from being called on the
>>>already-initialized object?
>>
>>The short answer: you can't:
>>     http://www.python.org/2.2.3/descrintro.html#__new__
> 
[snip]
This prompts a similar query.  __new__ appears to be intended for 
immutable objects but it seems to be called as part of constructor 
process for all instances.

Regarding the original question.  It is not possible to prevent the use 
of __init__ but is it possible to prevent __init__ having any effect by 
setting a flag when __init__ is called for the first creation of the 
instance.

Colin W.
> 



More information about the Python-list mailing list