making a class return None from __init__

Erik Max Francis max at alcyone.com
Fri Oct 4 20:16:47 EDT 2002


Aahz wrote:

> In article <3D9E0E80.36F8E03D at alcyone.com>,
> Erik Max Francis  <max at alcyone.com> wrote:
>
> >The proper way to handle this case is to raise an exception from the
> >constructor if something goes wrong.
> 
> __init__() is *NOT* a constructor, it's an initializer.  If you want a
> constructor, inherit from object and use __new__().

It's a constructor in the same way that a C++ or Java constructor is
one; this is standard terminology.  By the time the constructor gets
called, the object has already been created.  Strictly speaking it's an
initializer.  __new__ would be analogous to an overridden operator new
in C++, which is _not_ a constructor.

If you are trying to make a point that the role what is usually called a
"constructor" is really more along the lines of an initializer, the
point is well-taken, but I was using standard terminology in the
accepted way.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ The people are to be taken in very small doses.
\__/ Ralph Waldo Emerson
    The laws list / http://www.alcyone.com/max/physics/laws/
 Laws, rules, principles, effects, paradoxes, etc. in physics.



More information about the Python-list mailing list