no return values for __init__ ??
Helge Hess
helge at mdlink.de
Thu Jan 6 16:14:18 EST 2000
"Samuel A. Falvo II" wrote:
>
> Because __init__() is a constructor; it is called _after_ the object is
> already allocated and minimally initialized. So when __init__( self, ... )
> is called, "self" already contains a reference to the object which you are
> initializing.
>
> It is not __init__()'s job to allocate the object.
I can call __init__ like any other method and in fact it is a usual
method. So the only specialty about a constructor in Python is that it
is automatically invoked at class execution.
In fact is see '__init__' as practically the same as the '__call__'
special method, only that __call__ works on instances while __init__
works on classes.
Only to be sure that we don't misunderstand: it's absolutly clear to me
that returning a new object from __init__ will instantly deallocate the
current object if it isn't stored by a side-effect. I don't consider
this very problematic since: a) this will be used in a restricted
problem domain only, b) loosing programmer convenience is worse (he has
to learn two objects instead of one) and c) the overhead for object
allocation/deallocation is very low compared to other operations in
Python.
best regards
Helge
More information about the Python-list
mailing list