Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

To downgrade the human mind is bad theology. -- C. K. Chesterton


devel / comp.lang.python / Re: Object in List : how?

SubjectAuthor
o Re: Object in List : how?2QdxY4RzWzUUiLuE

1
Re: Object in List : how?

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

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=23359&group=comp.lang.python#23359

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: 2QdxY4RzWzUUiLuE@potatochowder.com
Newsgroups: comp.lang.python
Subject: Re: Object in List : how?
Date: Sun, 24 Jul 2022 23:28:30 -0500
Lines: 26
Message-ID: <mailman.85.1658724730.20444.python-list@python.org>
References: <CAB1Fbo2zE932BQZ8Dc794E35TtBJCC5krCzw+=3ep1mabzmW0w@mail.gmail.com>
<65239cb1-4baf-bad4-d7da-4d43c77335ad@web.de>
<CAB1Fbo1GW00e2fV089PbsO0MdKCQD_8v-7Zqpvkv1Kp6NYvJSg@mail.gmail.com>
<Yt4b7vk0YmvHvNdX@anomaly>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
X-Trace: news.uni-berlin.de WwwWU6MpyXAWfo/oF53l7QBhvN7wpHiPmDaLmfinPnQw==
Return-Path: <2QdxY4RzWzUUiLuE@potatochowder.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=none reason="no signature";
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.004
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'def': 0.04; 'parameter':
0.05; 'received:78': 0.09; 'subject:how': 0.09; '(because': 0.16;
'apis': 0.16; 'arguments': 0.16; 'default;': 0.16; 'expose': 0.16;
'from:addr:2qdxy4rzwzuuilue': 0.16; 'from:addr:potatochowder.com':
0.16; 'received:136.243': 0.16; 'received:78.46': 0.16;
'received:www458.your-server.de': 0.16; 'received:your-server.de':
0.16; 'wrote:': 0.16; 'instead': 0.17; 'uses': 0.19; 'to:addr
:python-list': 0.20; 'option': 0.20; 'creation': 0.22; 'skip:_
10': 0.22; 'received:de': 0.23; 'classes': 0.26; 'object': 0.26;
'else': 0.27; 'comment': 0.31; 'default': 0.31; 'concept': 0.32;
'received:136': 0.32; 'but': 0.32; 'there': 0.33; 'particular':
0.33; 'header:In-Reply-To:1': 0.34; "it's": 0.37; 'class': 0.37;
'two': 0.39; 'use': 0.39; 'exact': 0.40; 'to:': 0.62; 'supply':
0.65; 'right': 0.68; 'below': 0.69; 'subject:List': 0.71;
'relevant': 0.73; 'subject: : ': 0.81; 'received:70': 0.84
Mail-Followup-To: python-list@python.org
Content-Disposition: inline
In-Reply-To: <CAB1Fbo1GW00e2fV089PbsO0MdKCQD_8v-7Zqpvkv1Kp6NYvJSg@mail.gmail.com>
X-Authenticated-Sender: 2QdxY4RzWzUUiLuE@potatochowder.com
X-Virus-Scanned: Clear (ClamAV 0.103.6/26611/Sun Jul 24 09:58:48 2022)
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: <Yt4b7vk0YmvHvNdX@anomaly>
X-Mailman-Original-References: <CAB1Fbo2zE932BQZ8Dc794E35TtBJCC5krCzw+=3ep1mabzmW0w@mail.gmail.com>
<65239cb1-4baf-bad4-d7da-4d43c77335ad@web.de>
<CAB1Fbo1GW00e2fV089PbsO0MdKCQD_8v-7Zqpvkv1Kp6NYvJSg@mail.gmail.com>
 by: 2QdxY4RzWzUUiLuE@potatochowder.com - Mon, 25 Jul 2022 04:28 UTC

On 2022-07-24 at 19:47:38 -0500,
Khairil Sitanggang <ksit70@gmail.com> wrote:

> Regarding [Peter Otten's] comment : "
> *However, usually object creation and initialization iscombined by allowing
> arguments to the initializer:*" , so which one of the two classes Node1,
> Node2 below is more common in practice? Option 2, I guess.

No. Please use option 1.

Another option would be to expose b as an optional parameter with a
default value:

class Node:
def __init__(self, a, b=0):
self.a = a
self.b = self.calculation() if b == 0 else b

There are other ways to write that particular assignment to b (because
the default is 0), but the relevant concept for right now is that
callers *can* supply a value for b, but that they don't *have* to:

n1 = Node(a) # uses a default value for b
n2 = Node(a, 22) # overrides the default; use 22 instead

Designing APIs can be tricky, and it's not an exact science.


devel / comp.lang.python / Re: Object in List : how?

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor