Calling constructor but not initializer

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Fri Sep 21 19:33:35 EDT 2007


On Fri, 21 Sep 2007 10:47:02 -0400, Steve Holden wrote:

[snippity-doo-dah]

>> but of course __init__ is automatically called.
>> 
>> 
>> Any suggestions for doing something like this?
>> 
>> 
> Easy: use a method whose name is something other than __init__, then
> don't bother to implement __init__. Note that __new__ shouldn't call
> __init__ anyway, that's done by the instance creation mechanism.

*stares at post*

You know, I must have been REALLY tired last night, because that is 
extraordinarily obvious.

Even more obvious is not to use __new__ at all, and just wrap the body of 
the __init__ in an "if instance should not be empty" clause.

Thanks to everyone for answering my stupid question without laughing.


-- 
Steven.



More information about the Python-list mailing list