Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

"Your butt is mine." -- Michael Jackson, Bad


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

SubjectAuthor
o Re: Behavior of the for-else constructAvi Gross

1
Re: Behavior of the for-else construct

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: avigr...@verizon.net (Avi Gross)
Newsgroups: comp.lang.python
Subject: Re: Behavior of the for-else construct
Date: Fri, 4 Mar 2022 23:23:54 +0000 (UTC)
Lines: 67
Message-ID: <mailman.179.1646436240.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>
<1277767760.379444.1646412189311@mail.yahoo.com>
<CAPTjJmpGph9woqQGnkoE9=auFw49UqYMr3OxbhK24LytUgdyEA@mail.gmail.com>
<1957563644.11129.1646427163819@mail.yahoo.com>
<d95a8e00-c846-596e-11af-6d587cbfa249@btinternet.com>
<1359166284.39320.1646436234935@mail.yahoo.com>
Reply-To: Avi Gross <avigross@verizon.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
X-Trace: news.uni-berlin.de ztCVtdbiDoXbnusV9iVCDgTsXQUqoUnTxNjrjP/bRnsw==
Return-Path: <avigross@verizon.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=verizon.net header.i=@verizon.net header.b=D1armvj6;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.009
X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'looks': 0.02; '2022':
0.05; 'variable': 0.05; 'loop': 0.07; 'mar': 0.07; 'construct':
0.09; 'else:': 0.09; 'fails': 0.09; 'readable': 0.09;
'situations': 0.09; 'skip:` 10': 0.09; 'coding': 0.13;
'url:mailman': 0.15; 'avi': 0.16; 'directories': 0.16; 'dividing':
0.16; 'found.': 0.16; 'general.': 0.16; 'gross': 0.16; 'idea.':
0.16; 'idiom': 0.16; 'iterate': 0.16; 'languages.': 0.16;
'practically': 0.16; 'print(x)': 0.16; 'rarely.': 0.16;
'semantics': 0.16; 'sounds': 0.16; 'splitting': 0.16;
'subject:else': 0.16; 'toy,': 0.16; 'variable,': 0.16;
'variable.': 0.16; 'wrote:': 0.16; 'calls': 0.19; 'to:addr:python-
list': 0.20; 'exception': 0.22; 'fri,': 0.22; 'maybe': 0.22;
'code': 0.23; 'run': 0.23; 'to:name:python-list@python.org': 0.24;
'skip:- 10': 0.25; 'url-ip:188.166.95.178/32': 0.25; 'url-
ip:188.166.95/24': 0.25; 'depends': 0.25; 'url:listinfo': 0.25;
'programming': 0.25; 'url-ip:188.166/16': 0.25; 'behavior': 0.26;
'normally': 0.26; 'else': 0.27; 'local': 0.27; 'bit': 0.27;
'function': 0.27; 'done': 0.28; 'suggest': 0.28; 'it,': 0.29;
'attempt': 0.31; 'approach': 0.31; 'url-ip:188/8': 0.31;
'wondering': 0.31; 'course.': 0.32; 'empty': 0.32; 'python-list':
0.32; 'zero': 0.32; 'but': 0.32; 'subject:for': 0.33; 'path':
0.33; 'mean': 0.34; 'header:In-Reply-To:1': 0.34; 'trying': 0.35;
'handling': 0.35; 'yes,': 0.35; 'people': 0.36; 'using': 0.37;
"it's": 0.37; 'way': 0.38; 'list': 0.39; 'use': 0.39; 'break':
0.39; 'neither': 0.39; 'case.': 0.40; 'wishes': 0.40; 'both':
0.40; 'something': 0.40; 'try': 0.40; 'including': 0.60; 'best':
0.61; 'likely': 0.61; 'method': 0.61; 'from:': 0.62; 'to:': 0.62;
'here': 0.62; 'days': 0.62; 'copy': 0.63; 'complete': 0.64; 're:':
0.64; 'your': 0.64; 'similar': 0.65; 'well': 0.65; 'less': 0.65;
'let': 0.66; 'earlier': 0.67; 'back': 0.67; 'right': 0.68;
'accurately': 0.69; 'and,': 0.69; 'candidate': 0.69; 'times':
0.69; 'compared': 0.71; 'content': 0.72; 'plus': 0.73; 'yes':
0.76; 'sent:': 0.78; 'header:Reply-To:1': 0.79; 'leads': 0.81;
'unusual': 0.81; 'happens': 0.84; '20:52,': 0.84; '5:22': 0.84;
'clause': 0.84; 'exceptions': 0.84; 'method,': 0.84; 'rob': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=verizon.net; s=a2048;
t=1646436238; bh=4kJQNhqsx6qSBiCs6DfZTRt9I1G3HJjruNiP0cSlywE=;
h=Date:From:Reply-To:To:In-Reply-To:References:Subject:From:Subject:Reply-To;
b=D1armvj6NJNb5L9oNIKl7iQkwE9w6LLx7/+NBdDrzBJp49o1nQcyhRxHMKWF8P2C00F0taGBTMO5uQE0i9d2j6WS+2ASebd78Msfs4dgOBULIyfauWK8SYhXA9AJnMMoWy+WAvhPfUIXRx61afrjk1Y5SkWQzfUQVaFIaa6A4aBf2T9oh1fdlugO82GO/+WF0t5J3W2ctecfryyxcMcGxPxIsFL9ckBlW/emlMf1ETCHljgrWWbg5QB0XrZae8vckZd+7QiKJK0oDCIofdYvnpEZ9k8qcIzKnPu2xloQoPuttRZKcgdmmMJxa1APBUY6GIseHXf0dYXKXIhf1hKmzA==
X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048;
t=1646436238; bh=V7LZm2vvzbYscyHP36f0wpVQGMKDynGPHidNTlcXCJk=;
h=X-Sonic-MF:Date:From:To:Subject:From:Subject;
b=Oelme+oLs55/B7zqO9oAe19jHKXm3IEeiyN3+x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vPfMcBav33FNiLan2diKk7pZ.pDKWl_.WS04jjHWtGGKFNfIhN2WL6j89abiDc
bOMvFvg0DoxFuW4brrc4XkIpA0c7cG9F_HbliUbd30YzBhmWTpgywJ1._R9PmUhHu.6x_43hoslr
m2eRGe6TqPzKBeq8jXI3WouVwXjUCoor8UzopC15n15Yr2v2xRL_vN0394ERzSl7HnRiYkojADaZ
UfWgc4YUAEP7nY_kZAtWgvfp3NNs_be6GLWov_oOJA.XXTr4Oarc7eWxDDO7k6Sp4JnQoHlX4Psq
OVMC_ESgPt70O0VnwcLLl_U8mrVWvVseAPQUivJwXPNiDNDVRq.rKYrJFmHL80w1aUf1gRJ5nKGT
j_Wr.6ZZ7BJCMGazpjKPNPNnffnhSl5yHVfuZnycs4ZdKH589M0lNqCjn5xgHEMucq44VBN.Js2B
ZptY0FXiWBSS1TynavFnr6ThXV2ceR3U-
X-Sonic-MF: <avigross@verizon.net>
In-Reply-To: <d95a8e00-c846-596e-11af-6d587cbfa249@btinternet.com>
X-Mailer: WebService/1.1.19797 aolwebmail
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: <1359166284.39320.1646436234935@mail.yahoo.com>
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>
<1277767760.379444.1646412189311@mail.yahoo.com>
<CAPTjJmpGph9woqQGnkoE9=auFw49UqYMr3OxbhK24LytUgdyEA@mail.gmail.com>
<1957563644.11129.1646427163819@mail.yahoo.com>
<d95a8e00-c846-596e-11af-6d587cbfa249@btinternet.com>
 by: Avi Gross - Fri, 4 Mar 2022 23:23 UTC

Yes, Rob,

I keep wondering how many decades it will take before people here understand how I make a point with an example that is not intended in any way to be complete or the way I would do it.

No, I would not normally use the exception method, let alone in this case. This one practically screams for the method you suggest and iterate on a list of directories made from splitting the PATH variable. And, yes that method would likely use a for loop with a break if it is found and is a candidate for using the ELSE clause to note it has not been found.

But it is not an unusual idiom these days to use exceptions in places I never dreamed of in my earlier programming languages. A common example is always testing before accidentally dividing by zero and now code that depends on throwing the right exception and dealing with it, especially if the exception happens rarely.

So in situations where almost all programs are found in the first component of PATH, perhaps the exception approach is not horrible. It may even at times be done with less coding effort than other alternatives. Not my preferred way, of course.

-----Original Message-----
From: Rob Cliffe via Python-list <python-list@python.org>
To: python-list@python.org
Sent: Fri, Mar 4, 2022 5:22 pm
Subject: Re: Behavior of the for-else construct

On 04/03/2022 20:52, Avi Gross via Python-list wrote:
>
> I have an observation about exception handling in general. Some people use exceptions, including ones they create and throw, for a similar idea. You might for example try to use an exception if your first attempt fails that specifies trying the next attempt. In my example of the PATH variable, you might use something like calling a function and giving it what you are looking for as well as a local copy of the PATH variable content and the exception would be to call the function again with the first component of PATH removed until you fail with an empty PATH. Yes, this is similar to just having a recursive function.
That sounds neither readable nor efficient compared with using split()
plus a loop.  Maybe you mean this to be a toy, unrealistic example?
> So the example tossed at us looks a bit more like this and it does run the ELSE not because the loop is not done but because  the loop never calls a break:
>
> for x in range(0):
>    print(x)
> else:
>    print("Finally finished!")
This would be more readable with a `zeroiterations` keyword, which
accurately describes both the semantics and the intent.
> Which leads me right back to wondering why the sentinel approach is so bad!
>
>
It's not that bad, but it's more convenient and readable if it can be
avoided.
Best wishes
Rob Cliffe

--
https://mail.python.org/mailman/listinfo/python-list

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor