Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #65135 > unrolled thread
| Started by | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| First post | 2014-01-31 19:33 +0000 |
| Last post | 2014-02-02 18:34 -0500 |
| Articles | 3 — 3 participants |
Back to article view | Back to comp.lang.python
__init__ is the initialiser Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-01-31 19:33 +0000
Re: __init__ is the initialiser Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-02-03 12:23 +1300
Re: __init__ is the initialiser Roy Smith <roy@panix.com> - 2014-02-02 18:34 -0500
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2014-01-31 19:33 +0000 |
| Subject | __init__ is the initialiser |
| Message-ID | <mailman.6215.1391196811.18130.python-list@python.org> |
From http://docs.python.org/3/reference/datamodel.html#object.__init__ which states:- " Called when the instance is created. The arguments are those passed to the class constructor expression. If a base class has an __init__() method, the derived class’s __init__() method, if any, must explicitly call it to ensure proper initialization of the base class part of the instance; for example: BaseClass.__init__(self, [args...]). As a special constraint on constructors, no value may be returned; doing so will cause a TypeError to be raised at runtime. " Should the wording of the above be changed to clearly reflect that we have an initialiser here and that __new__ is the constructor? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence
[toc] | [next] | [standalone]
| From | Gregory Ewing <greg.ewing@canterbury.ac.nz> |
|---|---|
| Date | 2014-02-03 12:23 +1300 |
| Message-ID | <bl82apFh3sbU1@mid.individual.net> |
| In reply to | #65135 |
Mark Lawrence wrote: > Called when the instance is created. The arguments are those passed to > the class constructor expression. If a base class has an __init__() > method, the derived class’s __init__() method, if any, must explicitly > call it to ensure proper initialization of the base class part of the > instance; for example: BaseClass.__init__(self, [args...]). As a special > constraint on constructors, no value may be returned; doing so will > cause a TypeError to be raised at runtime. > " > > Should the wording of the above be changed to clearly reflect that we > have an initialiser here and that __new__ is the constructor? The first instance of "constructor" in that paragraph refers to the expression used to instantiate an object, e.g. 'MyClass(foo, blarg)', which is fine. The second instance might be clearer if it said "as a special constraint on the __init__ method" and avoided the word "constructor" altogether. Generally I think it would be better to talk about "the __new__ method" and "the __init__ method", and not call either of them a constructor. -- Greg
[toc] | [prev] | [next] | [standalone]
| From | Roy Smith <roy@panix.com> |
|---|---|
| Date | 2014-02-02 18:34 -0500 |
| Message-ID | <roy-42381F.18342502022014@news.panix.com> |
| In reply to | #65293 |
In article <bl82apFh3sbU1@mid.individual.net>, Gregory Ewing <greg.ewing@canterbury.ac.nz> wrote: > Generally I think it would be better to talk about "the > __new__ method" and "the __init__ method", and not call > either of them a constructor. +1
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web