Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

There are some things worth dying for. -- Kirk, "Errand of Mercy", stardate 3201.7


devel / comp.lang.python / Re: Behavior of the for-else construct

SubjectAuthor
o Re: Behavior of the for-else constructRoel Schroeven

1
Re: Behavior of the for-else construct

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: roe...@roelschroeven.net (Roel Schroeven)
Newsgroups: comp.lang.python
Subject: Re: Behavior of the for-else construct
Date: Fri, 4 Mar 2022 09:54:11 +0100
Lines: 41
Message-ID: <mailman.156.1646384057.2329.python-list@python.org>
References: <CALq4Z0-fJk-HOu0ka2kPrOioPYAh3e3zbziwetUDmAAx1U1LMw@mail.gmail.com>
<YiFCPlGC+2aRIR0K@shallowsky.com>
<21739669.459456.1646348879560@mail.yahoo.com>
<e3544242-cd54-05d3-2101-5b9fedc1c13e@btinternet.com>
<25121.48093.26762.592197@ixdm.fritz.box>
<CAPTjJmp0BQ0y5atoJS5+NK2zt3RQr7G4r=5=XHzGq8SCcXcUYA@mail.gmail.com>
<34231cf9-118a-d0ea-1a41-4e4bd80aa92e@roelschroeven.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de ddA2pBg/Q0ia+DOc7iHapA3uQzq04GsisnFeeHJN57ng==
Return-Path: <roel@roelschroeven.net>
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=roelschroeven.net header.i=@roelschroeven.net
header.b=L0Zo8BX0; dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.002
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'traceback': 0.04; '(most':
0.05; '2022': 0.05; 'last):': 0.05; 'variable': 0.05; 'loop':
0.07; 'mar': 0.07; 'cases.': 0.09; 'else:': 0.09; 'situations':
0.09; 'arbitrary': 0.16; 'demonstrated': 0.16; 'dieter': 0.16;
'franklin': 0.16; 'initialize': 0.16; 'loop?': 0.16; 'named.':
0.16; 'received:10.202': 0.16; 'received:10.202.2': 0.16;
'received:internal': 0.16; 'received:messagingengine.com': 0.16;
'schreef': 0.16; 'subject:else': 0.16; 'wrote:': 0.16; 'solve':
0.19; 'to:addr:python-list': 0.20; 'fri,': 0.22; "what's": 0.22;
'solution.': 0.26; '>>>': 0.28; 'chris': 0.28; 'example,': 0.28;
'this?': 0.29; 'header:User-Agent:1': 0.30; 'think': 0.32; '"",':
0.32; 'empty': 0.32; 'encountered': 0.32; 'guess': 0.32; 'but':
0.32; 'subject:for': 0.33; 'header:In-Reply-To:1': 0.34;
'particularly': 0.35; 'following': 0.35; 'received:66': 0.35;
'cases': 0.36; "it's": 0.37; 'hard': 0.37; 'file': 0.38; 'could':
0.38; 'put': 0.38; 'use': 0.39; 'want': 0.40; 'method': 0.61;
'proposal.': 0.62; 'reasonable': 0.62; 'ever': 0.63; 'pass': 0.64;
'involve': 0.64; 'it:': 0.69; 'perfectly': 0.69; 'sequence': 0.69;
'jones': 0.78; 'none"': 0.84; 'criticism': 0.91; 'expensive':
0.91; 'placing': 0.91; 'friend,': 0.95
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=
roelschroeven.net; h=cc:content-transfer-encoding:content-type
:date:date:from:from:in-reply-to:in-reply-to:message-id
:mime-version:references:reply-to:sender:subject:subject:to:to;
s=fm2; bh=q0iJSfXqzNGeQJCE3TquPGM8QO3ULbYGnJ0q/bo2EUk=; b=L0Zo8
BX0WLJmGo/8H6QS+FqUtDnL6uTmp/d74HlrSp56V1Nma5qHo8vJ46y9jpJiQgw1l
f4+NcURd4YbU/ntyOGwy2x0PtnAsVmmnaML5kEeoO3fhzIb+8Ex0++rgcCszre93
olKpq2frjTD9ZwCCOXNIx+fGiG8Iydtq5UbdvhgH4NkqZbKEe0ZDTSWYweb7cR6o
SOBBqt7EdIcVFcNd/BUF6zbiQ30U+aiqSe7OEMLHI5JxIMXcjpv3rtU6ca25jssC
cFzyBGMzo6kxC/qSFsf+ZaOtI+mqQdRTL1/MPDeaKBXYMRmkAEvTW1FdOL4zzxlP
svmzkbXHqlOYsQcqw==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=
messagingengine.com; h=cc:content-transfer-encoding:content-type
:date:date:from:from:in-reply-to:in-reply-to:message-id
:mime-version:references:reply-to:sender:subject:subject:to:to
:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=
fm2; bh=q0iJSfXqzNGeQJCE3TquPGM8QO3ULbYGnJ0q/bo2EUk=; b=NIi+9IoJ
kvFXrKVprL85pci0GH0X0AJL41Qp3ptnSUbEQSQFbSyuV9Oe4yZTZh6iQ0SQV7Pf
K80Yl7T9BNJEN71f4jLMcnmq2U3W8WrobssIlVptcLZiAyXQNb8wmhXcBAt/qmyb
OzpPbsRwTjbZ6WPgwH8eTCoEA1V5vHCgbTeLaibigg5GfmXS/Ti3tw8OQainRg9k
iexPR5Md8HjI+zZW75t8kqUSt2EOyB6+HI8YlDczKZE85u1K2dvGr487NoaB8ctF
hL8cmjwrJmhRqjoHCf3N5it7yPPNh2MFSGJ07roly9jqymqrnCEbRVOue0O7z9QS
pfyuS7temKV0gA==
X-ME-Sender: <xms:ttMhYhTt5lM1hWeTv5_tew6C2RSNZgbpFhPEJIOBd6ZH82TvkF2NxA>
<xme:ttMhYqwFuWDfCSNfzb1ApOF_gj2oQmwTeWCVItRc6brEaxzOfWom8K2qCJPFYJNrf
E4o0Qir_7Ue>
X-ME-Received: <xmr:ttMhYm1K0MMncqJ2gYJBepqGnPDkzq8eBMg_I_aoodDdiF9phmnKHSYoMhcZsG4yK7Q_A5mKllUiLU0riMQLqhrsdgli05VUrAO-lxPLULLFab8>
X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddruddtjedguddviecutefuodetggdotefrod
ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh
necuuegrihhlohhuthemuceftddtnecunecujfgurhepkfffgggfuffvfhfhjggtgfesth
ejredttdefjeenucfhrhhomheptfhovghlucfutghhrhhovghvvghnuceorhhovghlsehr
ohgvlhhstghhrhhovghvvghnrdhnvghtqeenucggtffrrghtthgvrhhnpeetueejffetud
efieetvefhgfetvdegieejkeejuedtvefhvedvudeutdetteduieenucevlhhushhtvghr
ufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehrohgvlhesrhhovghlshgthh
hrohgvvhgvnhdrnhgvth
X-ME-Proxy: <xmx:ttMhYpAK7elp0IsXpclLO_kVsL0jJFn6y-wQoR1tE-f_VCHouzftnQ>
<xmx:ttMhYqijbmrYhAY9yMuQZCjhez5-silGZsuE6UqzNzLSaKojDTaqwQ>
<xmx:ttMhYto668fc-_hHLga3ChRdEB7kFH4ooZvatdsiHdQLFH69T5ZuKQ>
<xmx:ttMhYgfC_3cbujtFQbVFNA8-Jo2-4rWOTabeDMJYNjmLBrFhnwdzPw>
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.6.1
Content-Language: nl
In-Reply-To: <CAPTjJmp0BQ0y5atoJS5+NK2zt3RQr7G4r=5=XHzGq8SCcXcUYA@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: <34231cf9-118a-d0ea-1a41-4e4bd80aa92e@roelschroeven.net>
X-Mailman-Original-References: <CALq4Z0-fJk-HOu0ka2kPrOioPYAh3e3zbziwetUDmAAx1U1LMw@mail.gmail.com>
<YiFCPlGC+2aRIR0K@shallowsky.com>
<21739669.459456.1646348879560@mail.yahoo.com>
<e3544242-cd54-05d3-2101-5b9fedc1c13e@btinternet.com>
<25121.48093.26762.592197@ixdm.fritz.box>
<CAPTjJmp0BQ0y5atoJS5+NK2zt3RQr7G4r=5=XHzGq8SCcXcUYA@mail.gmail.com>
 by: Roel Schroeven - Fri, 4 Mar 2022 08:54 UTC

Op 4/03/2022 om 8:18 schreef Chris Angelico:
> On Fri, 4 Mar 2022 at 18:13, Dieter Maurer <dieter@handshake.de> wrote:
> > One of my use cases for `for - else` does not involve a `break`:
> > the initialization of the loop variable when the sequence is empty.
> > It is demonstrated by the following transscript:
> >
> > ```pycon
> > >>> for i in range(0):
> > ... pass
> > ...
> > >>> i
> > Traceback (most recent call last):
> > File "<stdin>", line 1, in <module>
> > NameError: name 'i' is not defined
> > >>> for i in range(0):
> > ... pass
> > ... else: i = None
> > ...
> > >>> i
> > >>>
> > ```
> >
> > For this use case, `else` is perfectly named.
>
> What's the point of this? Why not just put "i = None" after the loop?
As I understand it: range(0) is just a (bad) example, it's actually
about any arbitrary iterable. You don't know in advance if it's empty or
not, and you want i to be initialized in all cases. (I don't think I
have ever encountered that situation.)

You could easily solve this by placing "i = None" before the loop, but I
guess in situations where you want to initialize i with the result of an
expensive operation Dieter's method could be a reasonable solution.

This would actually be a good use case for computermaster360's proposal.

--
"Honest criticism is hard to take, particularly from a relative, a friend,
an acquaintance, or a stranger."
-- Franklin P. Jones

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor