__init__ is the initialiser

Cameron Simpson cs at zip.com.au
Fri Jan 31 17:45:07 EST 2014


On 31Jan2014 12:57, Ethan Furman <ethan at stoneleaf.us> wrote:
> On 01/31/2014 12:48 PM, MRAB wrote:
> >On 2014-01-31 19:52, Ned Batchelder wrote:
> >>Why can't we call __init__ the constructor and __new__ the allocator?
> >
> >The advantage of calling it the "initialiser" is that it explains why
> >it's called "__init__".
> 
> Hm, yes, good point.  Also, __init__ initializes so it is a good choice.   Ignore the names comment in my previous post.

On this basis, would it suffice to change the opening sentence from:

  Called when the instance is created.

to

  Called to initialise a new instance immediately after creation.

?

This seems succinct while getting both "initialise" and "new" into
the line, which makes it clear that there is a separate and earlier
"new" step.  (Conveniently overridable with __new__ :-)

Cheers,
-- 
Cameron Simpson <cs at zip.com.au>

Don't have awk? Use this simple sh emulation:
    #!/bin/sh
    echo 'Awk bailing out!' >&2
    exit 2
- Tom Horsley <tahorsley at csd.harris.com>



More information about the Python-list mailing list