[Tutor] use of __new__
spir
denis.spir at free.fr
Fri Jun 12 15:52:16 CEST 2009
Le Fri, 12 Jun 2009 22:37:17 +1000,
Lie Ryan <lie.1296 at gmail.com> s'exprima ainsi:
> >>> class Normal(object):
> ... def __new__(cls, arg):
> ... if arg:
> ... return Special(arg)
> ... else:
> ... ret = super(Normal, cls).__new__(cls)
> ... ret.__init__(arg)
> ... return ret
> ... def __init__(self, arg):
> ... self.arg = arg
> ...
Forgot a question. You & I create and return a special object directly (above: "Special(arg)"). But the docs say we should use __new__ instead.
Denis
------
la vita e estrany
More information about the Tutor
mailing list