Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #65205

Re: __init__ is the initialiser

Date 2014-02-01 00:28 -0800
From Ethan Furman <ethan@stoneleaf.us>
Subject Re: __init__ is the initialiser
References <lcgtpf$tui$1@ger.gmane.org> <mailman.6217.1391197950.18130.python-list@python.org> <52ec6d1f$0$29972$c3e8da3$5496439d@news.astraweb.com> <mailman.6255.1391229320.18130.python-list@python.org> <52ec8b51$0$29972$c3e8da3$5496439d@news.astraweb.com>
Newsgroups comp.lang.python
Message-ID <mailman.6271.1391244676.18130.python-list@python.org> (permalink)

Show all headers | View raw


On 01/31/2014 09:51 PM, Steven D'Aprano wrote:
> On Sat, 01 Feb 2014 15:35:17 +1100, Chris Angelico wrote:
>>
>> The two methods could have been done as a single method, __construct__,
>> in which you get passed a cls instead of a self, and you call
>> self=super().__construct__() and then initialize stuff.
>
> That would be called __new__ in Python. There's no *need* to use __init__
> for anything (except old-style classic classes in Python 2).

While there may not be a /need/ for two, having two is quite handy.  Having __new__ take care of the nuts and bolts (or 
foundation, as Terry put it), and being able to further customize with __init__ (where the kitchen goes, how many 
bedrooms, to follow along with Terry) is quite useful.  One of my favorite Enum recipes uses that pattern to have some 
basic behavior, with some other behavior that is easily overridable/extendable [1].

--
~Ethan~

[1] http://stackoverflow.com/q/19330460/208880

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: __init__ is the initialiser Ned Batchelder <ned@nedbatchelder.com> - 2014-01-31 14:52 -0500
  Re: __init__ is the initialiser Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-02-01 03:42 +0000
    Re: __init__ is the initialiser Chris Angelico <rosuav@gmail.com> - 2014-02-01 15:35 +1100
      Re: __init__ is the initialiser Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-02-01 05:51 +0000
        Re: __init__ is the initialiser Ethan Furman <ethan@stoneleaf.us> - 2014-02-01 00:28 -0800
    Re: __init__ is the initialiser Ethan Furman <ethan@stoneleaf.us> - 2014-01-31 20:55 -0800
    Re: __init__ is the initialiser Ned Batchelder <ned@nedbatchelder.com> - 2014-02-01 07:28 -0500
      Re: __init__ is the initialiser Roy Smith <roy@panix.com> - 2014-02-01 09:40 -0500
        Re: __init__ is the initialiser Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-02-01 15:07 +0000
          Re: __init__ is the initialiser Roy Smith <roy@panix.com> - 2014-02-01 11:17 -0500
    Re: __init__ is the initialiser Tim Delaney <timothy.c.delaney@gmail.com> - 2014-02-02 07:09 +1100
      Re: __init__ is the initialiser Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-02-02 01:28 +0000
    Re: __init__ is the initialiser Ben Finney <ben+python@benfinney.id.au> - 2014-02-02 15:27 +1100
    Re: __init__ is the initialiser Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-02-03 12:38 +1300
      Re: __init__ is the initialiser Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-02-03 00:33 +0000
        Re: __init__ is the initialiser Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-02-04 12:47 +1300
    Re: __init__ is the initialiser Tim Delaney <timothy.c.delaney@gmail.com> - 2014-02-03 11:02 +1100

csiph-web