Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

6 May, 2024: The networking issue during the past two days has been identified and appears to be fixed. Will keep monitoring.


devel / comp.lang.python / Re: Optional arguments in a class behave like class attributes.

SubjectAuthor
o Re: Optional arguments in a class behave like class attributes.Chris Angelico

1
Re: Optional arguments in a class behave like class attributes.

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ros...@gmail.com (Chris Angelico)
Newsgroups: comp.lang.python
Subject: Re: Optional arguments in a class behave like class attributes.
Date: Tue, 18 Oct 2022 01:57:13 +1100
Lines: 24
Message-ID: <mailman.738.1666018646.20444.python-list@python.org>
References: <CAMmiCvKHJFfT2aST7tHZSX_Bc-XJx6wKey2DvP4BP=f4dSNX0Q@mail.gmail.com>
<CAPTjJmqebyX11aU8id-97VYwFpqiiG-HO16-u6-0HZtDoAecag@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de UHUC76PsFLWmi7Q1zWhp4gJu5vXkVGoQfYrctlTJP3/w==
Return-Path: <rosuav@gmail.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=gmail.com header.i=@gmail.com header.b=HimE8rWl;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.003
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'def': 0.04; '2022': 0.05;
'python.': 0.08; 'else:': 0.09; 'subject:class': 0.09;
'attributes,': 0.16; 'chrisa': 0.16; 'from:addr:rosuav': 0.16;
'from:name:chris angelico': 0.16; 'none:': 0.16;
'received:209.85.218': 0.16; 'syntax,': 0.16; 'wrote:': 0.16;
'values': 0.17; 'tue,': 0.19; 'to:addr:python-list': 0.20; 'skip:_
10': 0.22; 'version': 0.23; 'list,': 0.24; 'default': 0.31;
'message-id:@mail.gmail.com': 0.32; 'there': 0.33; 'proposal':
0.33; 'same': 0.34; 'header:In-Reply-To:1': 0.34;
'received:google.com': 0.34; 'from:addr:gmail.com': 0.35; 'using':
0.37; 'received:209.85': 0.37; 'class': 0.37; 'received:209':
0.39; 'single': 0.39; 'list': 0.39; 'something': 0.40; 'want':
0.40; 'here': 0.62; 'games': 0.70; "you'll": 0.73
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=to:subject:message-id:date:from:in-reply-to:references:mime-version
:from:to:cc:subject:date:message-id:reply-to;
bh=rcyMQWCErun9k97/Ldx9J2mMxprZakFEyOa2OJdPGR0=;
b=HimE8rWlmz/qoNdGoPwV7rTRoC+MDWDyBEtm3Pcq6xNH8mJ23Jjq74cTRCmutrLQAp
QPWoAP5UQenWXbov6Wekrt5kmoNauiNw83Ax95aWQu7/MFslWSy3aHEah4bcAIIDrJAG
72FPWEe2QxBjouriCwrxYF4Y3qpBa7Dp87F2Mkg19co05IGr4atJyAk9srN+8dtNa6bU
qmGxwYNoK/GMn4loDf+AqSt4thNTbkLI1NkIkmlDwC9Zx93yZSMS7i1RLgpQRq8yHF68
mUkCo+fDPB9c63z8azxvJP/DUBEKVx/tGdwqrfAeoLubBUf7qeLo7hVXhHDmeyZY/ALX
44kA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=to:subject:message-id:date:from:in-reply-to:references:mime-version
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
bh=rcyMQWCErun9k97/Ldx9J2mMxprZakFEyOa2OJdPGR0=;
b=rAIIxj7Jj/E1ZqsJNufhs1nQlx1qdIlvy2gRVCobPxh9M7upqMkUZiAghKP9uwjIMK
rEuI2NNVVBIBXQOzqWR8Cz0AbMj80j0DCvXEmWII0elBKw9FS7r1F5WWzE/u2uhHONkz
x5QQgOCfqSgpaWqM9jJmt8qmrBTrf5aGj2YT8IeaDbf22ozIM3J8KQy99kTH49rHYgrw
EJM34HUAAvWYtybutjYqdbf3vssfaGLJ1TSBKYlHaE9Rk1lpK1QUUWK+YcVKlCT+ixUx
YTzAXoHjmbX7rLPcznUodDevzg1gcAZLZZOiRaoIjs8LSfFWTCd/d0K5MA1eHw71HUe4
FPhg==
X-Gm-Message-State: ACrzQf0mGlVVE5I+LtPE5cH2DMTjh1EVwd5GZXiRsHrLtvxcW0ODlwkH
QBXE8s/ufXdZSGjHaKWBjoIVVYFqRoUMB0Ea6ezHXh7y
X-Google-Smtp-Source: AMsMyM7VVo1GcXt13q0TE2LoumgPVWHHEhJAgSIO+3MYpEUTZ6eQyaz4F8D3s3rQwOgXEyIcb7tTn9s+qj/pADuP+Bs=
X-Received: by 2002:a17:907:6da3:b0:78e:2a5f:5aaf with SMTP id
sb35-20020a1709076da300b0078e2a5f5aafmr8970681ejc.554.1666018644339; Mon, 17
Oct 2022 07:57:24 -0700 (PDT)
In-Reply-To: <CAMmiCvKHJFfT2aST7tHZSX_Bc-XJx6wKey2DvP4BP=f4dSNX0Q@mail.gmail.com>
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: <CAPTjJmqebyX11aU8id-97VYwFpqiiG-HO16-u6-0HZtDoAecag@mail.gmail.com>
X-Mailman-Original-References: <CAMmiCvKHJFfT2aST7tHZSX_Bc-XJx6wKey2DvP4BP=f4dSNX0Q@mail.gmail.com>
 by: Chris Angelico - Mon, 17 Oct 2022 14:57 UTC

On Tue, 18 Oct 2022 at 01:39, Abderrahim Adrabi
<abderrahim.adrabi@gmail.com> wrote:
> So, these default values behave like class attributes, here is a demo:
>
> # Using a list -----------------------------
> class GameOne:
> def __init__(self, games = []) -> None:
> self.games = games
>

This makes the default be a single list, the same list for all of
them. If you want the default to be "construct a new list", you'll
need something else:

def __init__(self, games=None):
if games is None: games = []

There is an open proposal to allow this syntax, which would do what you want:

def __init__(self, games=>[]):

However, this is not part of any current version of Python.

ChrisA

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor