Rocksolid Light

Welcome to Rocksolid Light

mail  files  register  newsreader  groups  login

Message-ID:  

Real Users find the one combination of bizarre input values that shuts down the system for days.


devel / comp.lang.python / Re: Why doc call `__init__` as a method rather than function?

SubjectAuthor
o Why doc call `__init__` as a method rather than function?anthony.flury

1
Re: Why doc call `__init__` as a method rather than function?

<mailman.319.1695008163.23016.python-list@python.org>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=24252&group=comp.lang.python#24252

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!nntp.comgw.net!fu-berlin.de!uni-berlin.de!not-for-mail
From: anthony.flury@btinternet.com (anthony.flury)
Newsgroups: comp.lang.python
Subject: Re: Why doc call `__init__` as a method rather than function?
Date: Fri, 15 Sep 2023 14:05:18 +0100 (BST)
Lines: 66
Message-ID: <mailman.319.1695008163.23016.python-list@python.org>
References: <OS3P286MB0740BDD307B9BEB732BD2256A5F6A@OS3P286MB0740.JPNP286.PROD.OUTLOOK.COM>
<6a907429.54af.18a98f21d8d.Webtop.90@btinternet.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: quoted-printable
X-Trace: news.uni-berlin.de 3r+MpWXqWDXari6jWfsrZAefC/T00vBYw9bUrvhSSXTw==
Cancel-Lock: sha1:ggGeX2FA4aRHaPs3yhTMBqStrlI= sha256:nLbLFUXcYdLW5V8LIBawDQBjtazS5DuEejOuFziCRZE=
Return-Path: <anthony.flury@btinternet.com>
X-Original-To: Python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=btinternet.com header.i=@btinternet.com header.b=VI96SJ2l;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: UNSURE 0.245
X-Spam-Level: **
X-Spam-Evidence: '*H*': 0.52; '*S*': 0.01; 'def': 0.04; 'subject:Why':
0.07; "shouldn't": 0.09; 'subject:doc': 0.09; 'url:mailman': 0.15;
'attributes': 0.16; 'doc': 0.16; 'expected.': 0.16; 'function...':
0.16; 'inspect': 0.16; 'instance': 0.16; 'runtime': 0.16;
'subject:call': 0.16; 'python': 0.16; 'to:addr:python-list': 0.20;
'maybe': 0.22; 'skip:_ 10': 0.22; 'thanks!': 0.24; 'to:name
:python-list@python.org': 0.24; 'url-ip:188.166.95.178/32': 0.25;
'url-ip:188.166.95/24': 0.25; 'url:listinfo': 0.25; 'url-
ip:188.166/16': 0.25; 'seems': 0.26; 'friday,': 0.26; 'object':
0.26; 'function': 0.27; 'output': 0.28; 'email
addr:python.org&gt;': 0.28; 'it,': 0.29; 'header:User-Agent:1':
0.30; 'url-ip:188/8': 0.31; 'think': 0.32; 'official': 0.32;
'but': 0.32; 'header:In-Reply-To:1': 0.34; 'book': 0.35;
'functions': 0.36; 'special': 0.37; 'really': 0.37; "it's": 0.37;
'class': 0.37; 'way': 0.38; 'mentioned': 0.39; 'use': 0.39;
'methods': 0.39; 'explain': 0.40; 'happen': 0.40; 'received:213':
0.40; 'both': 0.40; 'want': 0.40; 'method': 0.61; 'skip:0 20':
0.61; 'from:': 0.62; 'to:': 0.62; 'ever': 0.63; 'pass': 0.64;
'authors': 0.64; 'url-ip:104.18/16': 0.67; 'subject:method': 0.69;
'url:dtd': 0.74; 'url:xhtml': 0.74; 'features': 0.75; 'url:1999':
0.75; '&quot;a': 0.76; '------': 0.76; '....': 0.76;
'implemented': 0.76; 'sent:': 0.78; 'url:xhtml1': 0.83; '____':
0.84; 'anthony': 0.84; 'email name:&lt;python-list': 0.84;
'method,': 0.84; 'obj': 0.84; 'tao': 0.84; 'to:addr:hotmail.com':
0.84; 'tony': 0.84; 'subject:than': 0.91; 'url:xhtml1-strict':
0.91; 'newly': 0.93
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=btinternet.com;
s=btmx201904; t=1694783118;
bh=Mh6mYWoGQqp44w1nFJNWklskNJpfy0ZY2Q6C0kd6ErE=;
h=To:Message-ID:In-Reply-To:References:Subject:MIME-Version:From:Date;
b=VI96SJ2lCHaPuCARSbmNbDjRl/jgTJDaz0/vlAJdrpLRAaLEdBKac2p7hlUZtbV6Ni0sm35DCIxRzu6O7zcwBhF7Zi1EnPHPLaSV0wRMwto6eHAo5TtmjoS2/bsnOk2ve/ErlN47MFQzdhcLjLZPH038r2XnbzSgePZ+KJi2b2wZJN8n9XAN76V5MMdnGTvE0E9HD3CZPFrQSlsl94lO8D9XwzK+oRgN3FmFeDPjUExkzqjm1HDVWG2mA1NEoYKfyyeq7ms3ygSxVaJXAqFfTxIodgN5lXIBZket3GJbzOaj4ySWOqZwHiD0leS4xBGB6m52aSrGpOZaG+CkvDrZUA==
Authentication-Results: btinternet.com; none
X-SNCR-Rigid: 64CADCC5047192E8
X-OWM-Env-Sender: anthony.flury@btinternet.com
X-VadeSecure-score: verdict=clean score=0/300, class=clean
X-RazorGate-Vade: gggruggvucftvghtrhhoucdtuddrgedviedrudejvddgheekucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuueftkffvkffujffvgffngfevqffopdfqfgfvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefvkfgjfhfugggtfghihfffsegrtdersgdtreejnecuhfhrohhmpedfrghnthhhohhnhidrfhhluhhrhidfuceorghnthhhohhnhidrfhhluhhrhiessghtihhnthgvrhhnvghtrdgtohhmqeenucggtffrrghtthgvrhhnpeffgeeiueekfeetveeuhfetveefudfgiefgffevteduveevhfevgfehfeeugeevueenucffohhmrghinhepphihthhhohhnrdhorhhgnecukfhppedutddrvddrfeekrdeltddpkedurddugeejrdeikedrudeinecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehhvghlohepshgrqdhprhguqdhugihfvghpqddttdelrdgsthhmgidqphhrugdrshihnhgthhhrohhnohhsshdrnhgvthdpihhnvghtpedutddrvddrfeekrdeltddpmhgrihhlfhhrohhmpegrnhhthhhonhihrdhflhhurhihsegsthhinhhtvghrnhgvthdrtghomhdpnhgspghrtghpthhtohepvddprhgtphhtthhopefrhihthhhonhdqlhhishhtsehphihthhhonhdrohhrghdprhgtphhtthhopehstghruhgvlhhtsehhohhtmhgrihhlrdgtohhmpdhrvghvkffrpehsrgdqphhrugdquhigfhgvphdqtddtledqughmiidpoffv
tefjohhsthepshgrqdhprhguqdhrghhouhhtqddttdeh
X-RazorGate-Vade-Verdict: clean 0
X-RazorGate-Vade-Classification: clean
X-SNCR-hdrdom: btinternet.com
In-Reply-To: <OS3P286MB0740BDD307B9BEB732BD2256A5F6A@OS3P286MB0740.JPNP286.PROD.OUTLOOK.COM>
User-Agent: OWM Mail 3
X-SID: 90
X-Originating-IP: [81.147.68.16]
X-Mailman-Approved-At: Sun, 17 Sep 2023 23:36:02 -0400
X-Content-Filtered-By: Mailman/MimeDel 2.1.39
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
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: <https://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>
X-Mailman-Original-Message-ID: <6a907429.54af.18a98f21d8d.Webtop.90@btinternet.com>
X-Mailman-Original-References: <OS3P286MB0740BDD307B9BEB732BD2256A5F6A@OS3P286MB0740.JPNP286.PROD.OUTLOOK.COM>
 by: anthony.flury - Fri, 15 Sep 2023 13:05 UTC

To me __init__ is a method, but that is implemented internally as
function associated to a class

When you use A.__init__ on it's own and inspect it, then it will show
that it is a function object - this is expected. The implementation
internals of the runtime don't need to have a special implementation for
a method.

Like all of the other __<name>__ methods you shouldn't ever need to call
them directly : these are called dunder methods and represent functions
and features which are called by other operators.

The only recommended way to call A.__init__ is to create an instance of
A : obj = A() - the __init__ method gets called automatically with a
newly created object.

If you did call A.__init__() directly on a an already existing object :

obj = A()
A.__init__(obj)

for example - all that would happen is that the object itself would be
reset : ie the obj's attributes would be reset to whatever the __init__
sets them to - if you need to do that it might be better to have a reset
method.

Regards,

Tony

------ Original Message ------
From: "scruel tao via Python-list" <python-list@python.org>
To: "python-list@python.org" <Python-list@python.org>
Sent: Friday, 15 Sep, 23 At 11:49
Subject: Why doc call `__init__` as a method rather than function?
```python
class A:
.... def __init__(self):
.... pass
....
A.__init__
<function A.__init__ at 0x0000026CFC5CCEE0>
a = A()
a.__init__
<bound method A.__init__ of <__main__.A object at 0x0000026CFC1BB400>>
```
On many books and even the official documents, it seems that many
authors prefer to call `__init__` as a "method" rather than a
"function".
The book PYTHON CRASH COURSE mentioned that "A function that’s part of
a class is a method.", however, ` A.__init__` tells that `__init__` is a
function...
I wonder how can I call `__init__` as? Consider the output above.
Maybe both are OK? If you prefer or think that we must use one of the
two, please explain the why, I really want to know, thanks!
--
https://mail.python.org/mailman/listinfo/python-list
<https://mail.python.org/mailman/listinfo/python-list>

-- <br>Anthony Flury<br>anthony.flury@btinternet.com


devel / comp.lang.python / Re: Why doc call `__init__` as a method rather than function?

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor