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


Groups > comp.lang.python > #65141

Re: __init__ is the initialiser

Path csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python@mrabarnett.plus.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'example:': 0.03; 'explicitly': 0.05; 'differently': 0.07; 'initialize': 0.07; 'returned.': 0.07; '__init__': 0.09; 'arguments': 0.09; 'constructor': 0.09; 'derived': 0.09; 'lawrence': 0.09; 'method,': 0.09; 'python': 0.11; 'programs.': 0.14; '"python': 0.16; '__init__,': 0.16; '__new__': 0.16; 'created.': 0.16; 'expression.': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'initialiser': 0.16; 'instance;': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; "object's": 0.16; 'received:192.168.1.4': 0.16; 'returned;': 0.16; 'runtime.': 0.16; 'semantics': 0.16; 'torn': 0.16; 'variables,': 0.16; 'wording': 0.16; 'wrote:': 0.18; 'any,': 0.19; 'header:User- Agent:1': 0.23; 'class.': 0.26; 'gets': 0.27; 'header:In-Reply- To:1': 0.27; "i'm": 0.30; 'code': 0.31; 'that.': 0.31; 'raised': 0.31; 'class': 0.32; 'url:python': 0.33; 'beginning': 0.33; '"the': 0.34; 'sense': 0.34; 'subject:the': 0.34; "can't": 0.35; 'classes': 0.35; 'but': 0.35; 'add': 0.35; 'c++': 0.36; 'explains': 0.36; 'reflect': 0.36; 'doing': 0.36; 'method': 0.36; 'useful': 0.36; 'url:org': 0.36; 'should': 0.36; 'to:addr:python- list': 0.38; 'fact': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'changed': 0.39; 'called': 0.40; 'ensure': 0.60; 'most': 0.60; 'url:3': 0.61; "you're": 0.61; 'more': 0.64; 'here': 0.66; 'special': 0.74; '95%': 0.84; 'batchelder': 0.84; 'describes': 0.84; 'url:datamodel': 0.84; 'url:html#object': 0.84; 'url:reference': 0.84; 'tied': 0.93
X-CM-Score 0.00
X-CNFS-Analysis v=2.1 cv=eZmzft0H c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=5FYZ9MsUIQAA:10 a=ihvODaAuJD4A:10 a=IkcTkHD0fZMA:10 a=EBOSESyhAAAA:8 a=1U9r9e_U-9MA:10 a=8AHkEIZyAAAA:8 a=e7oSAV8Jh9418hQkascA:9 a=QEXdDO2ut3YA:10 a=35aIS-mj8JEA:10
X-AUTH mrabarnett:2500
Date Fri, 31 Jan 2014 20:48:10 +0000
From MRAB <python@mrabarnett.plus.com>
User-Agent Mozilla/5.0 (Windows NT 6.3; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0
MIME-Version 1.0
To python-list@python.org
Subject Re: __init__ is the initialiser
References <lcgtpf$tui$1@ger.gmane.org> <lcgut2$b8r$1@ger.gmane.org>
In-Reply-To <lcgut2$b8r$1@ger.gmane.org>
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 8bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.6221.1391201299.18130.python-list@python.org> (permalink)
Lines 45
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1391201299 news.xs4all.nl 2928 [2001:888:2000:d::a6]:35677
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:65141

Show key headers only | View raw


On 2014-01-31 19:52, Ned Batchelder wrote:
> On 1/31/14 2:33 PM, Mark Lawrence wrote:
>>  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?
>>
>
> I'm torn about that.  The fact is, that for 95% of the reasons you want
> to say "constructor", the thing you're describing is __init__.  Most
> classes have __init__, only very very few have __new__.
>
> The sense that __new__ is the constructor is the one borrowed from C++
> and Java: you don't have an instance of your type until the constructor
> has returned.  This is why __init__ is not a constructor: the self
> passed into __init__ is already an object of your class.
>
> But that distinction isn't useful in most programs.  The thing most
> people mean by "constructor" is "the method that gets invoked right at
> the beginning of the object's lifetime, where you can add code to
> initialize it properly."  That describes __init__.
>
> Insisting that __init__ is not a constructor makes about as much sense
> as insisting that "Python has no variables" just because they work
> differently than in C.  Python has variables, and it has constructors.
> We don't have to be tied to C++ semantics of the word "constructor" any
> more than we have to tied to its semantics of the word "variable" or "for".
>
> 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__".

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


Thread

Re: __init__ is the initialiser MRAB <python@mrabarnett.plus.com> - 2014-01-31 20:48 +0000

csiph-web