[Tutor] /not/ instanciating
Jerry Hill
malaclypse2 at gmail.com
Mon Nov 17 15:58:00 CET 2008
On Sun, Nov 16, 2008 at 2:57 PM, spir <denis.spir at free.fr> wrote:
> * Why, then, is __init__ still executed when the instanciated object is
> 'manually' returned? What's the use of that feature?
The manual (http://www.python.org/doc/2.5.2/ref/customization.html) says:
"If __new__() returns an instance of cls, then the new instance's
__init__() method will be invoked like "__init__(self[, ...])", where
self is the new instance and the remaining arguments are the same as
were passed to __new__(). "
That seems to explain why you're seeing what you're seeing. I don't
know how you would avoid that if that's not the behavior you want,
though. I suppose you could then repeat your check of the type of
source in __init__, just like you did in __new__ to avoid
re-initializing.
--
Jerry
More information about the Tutor
mailing list