Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

You can't go home again, unless you set $HOME.


devel / comp.lang.python / Single line if statement with a continue

SubjectAuthor
* Single line if statement with a continueAaron P
+- Re: Single line if statement with a continueStefan Ram
+- Re: Single line if statement with a continueChris Angelico
+- Re: Single line if statement with a continuedn
+* Re: Single line if statement with a continueThomas Passin
|`* Re: Single line if statement with a continueChris Green
| +* Re: Single line if statement with a continueStefan Ram
| |+- Re: Single line if statement with a continueCecil Westerhof
| |+- RE: Single line if statement with a continue<avi.e.gross
| |+- Re: Single line if statement with a continueWeatherby,Gerard
| |+* Re: Single line if statement with a continueMRAB
| ||`- Re: Single line if statement with a continueStefan Ram
| |`- Re: Single line if statement with a continueGrant Edwards
| `- Re: Single line if statement with a continueThomas Passin
+- Re: Single line if statement with a continueChris Angelico
+- RE: Single line if statement with a continue<avi.e.gross
+- Re: Single line if statement with a continueRob Cliffe
+- Re: Single line if statement with a continueAbdullah Nafees
+- Re: Single line if statement with a continuedn
+* RE: Single line if statement with a continue<avi.e.gross
|`- Re: Single line if statement with a continueTony Oliver
+- Re: Single line if statement with a continueThomas Passin
+- Re: Single line if statement with a continueChris Angelico
`* Re: Single line if statement with a continueDennis Lee Bieber
 `* Re: Single line if statement with a continueStefan Ram
  `- Re: Single line if statement with a continuePeter J. Holzer

Pages:12
Single line if statement with a continue

<af8635f1-30b9-4a0b-b9f8-d81f2c54960an@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.python
X-Received: by 2002:a05:622a:5a88:b0:3a5:46b0:ffec with SMTP id fz8-20020a05622a5a8800b003a546b0ffecmr89581202qtb.306.1671043990630;
Wed, 14 Dec 2022 10:53:10 -0800 (PST)
X-Received: by 2002:a05:6870:a44d:b0:144:6585:780e with SMTP id
n13-20020a056870a44d00b001446585780emr325357oal.85.1671043990291; Wed, 14 Dec
2022 10:53:10 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.python
Date: Wed, 14 Dec 2022 10:53:10 -0800 (PST)
Injection-Info: google-groups.googlegroups.com; posting-host=136.226.53.27; posting-account=Nsge0QoAAAAjlaxIDVrJIhCcRKA3uWrd
NNTP-Posting-Host: 136.226.53.27
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <af8635f1-30b9-4a0b-b9f8-d81f2c54960an@googlegroups.com>
Subject: Single line if statement with a continue
From: transreductionist@gmail.com (Aaron P)
Injection-Date: Wed, 14 Dec 2022 18:53:10 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1349
 by: Aaron P - Wed, 14 Dec 2022 18:53 UTC

I occasionally run across something like:

for idx, thing in enumerate(things):
if idx == 103:
continue
do_something_with(thing)

It seems more succinct and cleaner to use:

if idx == 103: continue.

Of course this would be considered an anti-pattern, and Flake8 will complain.

Any opinions, or feedback on the matter.

Re: Single line if statement with a continue

<Flake-20221214202851@ram.dialup.fu-berlin.de>

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.python
Subject: Re: Single line if statement with a continue
Date: 14 Dec 2022 19:30:08 GMT
Organization: Stefan Ram
Lines: 20
Expires: 1 Sep 2023 11:59:58 GMT
Message-ID: <Flake-20221214202851@ram.dialup.fu-berlin.de>
References: <af8635f1-30b9-4a0b-b9f8-d81f2c54960an@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de MxjN/7usBQNVUq8NyL8nhgSGU7+QD6r5xcAq1jCjqk93Kj
X-Copyright: (C) Copyright 2022 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE, en-US, it, fr-FR
 by: Stefan Ram - Wed, 14 Dec 2022 19:30 UTC

Aaron P <transreductionist@gmail.com> writes:
>It seems more succinct and cleaner to use:
>if idx == 103: continue.
>Of course this would be considered an anti-pattern, and Flake8 will complain.
>Any opinions, or feedback on the matter.

I think tools like Flake8 check whether the style adheres to
a certain set of style rules /for those users/ who like that
particular ruleset. I can see no harm in writing "if idx ==
103: continue" all on a single line. I think, if one adds

[flake8]
ignore = E701

to the configuration file of Flake8, it is possible that
this complaint will go away while other rules are still
being checked. But I have not tested this. Maybe it's not
the right number!

Re: Single line if statement with a continue

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: rosuav@gmail.com (Chris Angelico)
Newsgroups: comp.lang.python
Subject: Re: Single line if statement with a continue
Date: Thu, 15 Dec 2022 15:35:28 +1100
Lines: 21
Message-ID: <mailman.1169.1671078941.20444.python-list@python.org>
References: <af8635f1-30b9-4a0b-b9f8-d81f2c54960an@googlegroups.com>
<CAPTjJmp7itCdQQ76UQttWg_A8f5Y=NHnSBe_t_BFWXiQEP0nUw@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de cDa+BXEOVn2Mq7uwWNxvhgEomau0I0S9I7TTABfimodA==
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=QxtJsjd0;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.017
X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; '2022': 0.05;
'occasionally': 0.09; 'chrisa': 0.16; 'continue.': 0.16;
'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16;
'received:209.85.218': 0.16; 'subject:continue': 0.16; 'use:':
0.16; 'wrote:': 0.16; 'thu,': 0.19; 'to:addr:python-list': 0.20;
'feedback': 0.23; 'run': 0.23; 'seems': 0.26; 'matter.': 0.26;
'wrong': 0.28; 'dec': 0.31; 'message-id:@mail.gmail.com': 0.32;
'header:In-Reply-To:1': 0.34; 'received:google.com': 0.34;
'from:addr:gmail.com': 0.35; 'received:209.85': 0.37;
'received:209': 0.39; 'single': 0.39; 'something': 0.40; 'your':
0.64; 'accepting': 0.75; 'aaron': 0.84; 'cleaner': 0.84
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=ZnIzI6fai/AaHNurK/9YCzhvV4lpo0M5SWpWQKD2OAo=;
b=QxtJsjd0ttAJXFmMLqZj0QuGHuc2jJs7DUSqUImssF3LTnuN2IlH4/aBs7Oj7Wb6vP
YmWfcu+nCi6Svg01vY9eKNsPbdWwA9stnxMrWgpp/a3R0TvmrJhrP44CaAFcv7AeEnCb
6oKICULaw44LntT246YlUTUP/jDgTfyz1WQmi8l9HFmtzrf7DnAyhe/qZIaLQeOnnXJS
xbanbsAIck15pYuC2ejvXXJd3lxSoyZtxYftoxt09/gQ1Ts8495/vhENN5hTYNZFwTA9
ovWc+/mme+Bbcco8kJrtuHwZrGhPzYhwm6T1mCtA0oTsMVZnd63Eyu0/FPSyDyaL4GMI
IGsA==
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=ZnIzI6fai/AaHNurK/9YCzhvV4lpo0M5SWpWQKD2OAo=;
b=FQDP/15e6O4CDe82WiJdBVh1VgI0linh05DlPSb6rwF6o9EuFpvW+Wt9VCuWFK6mbQ
6cUPriQSglft+xkHq/WWjTQoFBfwAFPjz+l/jt2G0QTWGOQt9WHJ3Vy9ooHKI6EkEiWX
6vLdkd34ApfG0yx9RvHfE5gbKka/c3Yn1w5YyhPHetFT5Sd4P8ek3ARICugqZxsyqE/9
5GO0Ta3faLnAzt3aN19quqtI+APsOAnZkyhcKLPwn+hoy8MrKrk6wnvaLuDzjO7i+NvL
sYCwOw2eXs1hm8W15i5+bJUssVoMMtKyGjwXPQZ+nXbYZxgCQiaDEpJILNlFotTgs2Qn
pi8g==
X-Gm-Message-State: ANoB5pmm2+JYF1M7o6bCUye9oLX3bXM6nF/GU9U/g1E45+cz5W2k/mNh
sJdWzQ6obLyWiof7ddUAqJw0/Ppz5ykYzfX80L00gEeo
X-Google-Smtp-Source: AA0mqf7Rx7WfrKu2lO2HGARUM1DFbjuFoOJUtp604EMbPxL0XI+iUwqr+OmtLu0fcsYY22tWNzqpMQnJO08gD8yJ294=
X-Received: by 2002:a17:906:f281:b0:7ae:3b9e:1d8a with SMTP id
gu1-20020a170906f28100b007ae3b9e1d8amr77852286ejb.581.1671078939252; Wed, 14
Dec 2022 20:35:39 -0800 (PST)
In-Reply-To: <af8635f1-30b9-4a0b-b9f8-d81f2c54960an@googlegroups.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: <CAPTjJmp7itCdQQ76UQttWg_A8f5Y=NHnSBe_t_BFWXiQEP0nUw@mail.gmail.com>
X-Mailman-Original-References: <af8635f1-30b9-4a0b-b9f8-d81f2c54960an@googlegroups.com>
 by: Chris Angelico - Thu, 15 Dec 2022 04:35 UTC

On Thu, 15 Dec 2022 at 14:41, Aaron P <transreductionist@gmail.com> wrote:
>
> I occasionally run across something like:
>
> for idx, thing in enumerate(things):
> if idx == 103:
> continue
> do_something_with(thing)
>
> It seems more succinct and cleaner to use:
>
> if idx == 103: continue.
>
> Of course this would be considered an anti-pattern, and Flake8 will complain.
>
> Any opinions, or feedback on the matter.

Nothing at all wrong with writing that on a single line. If you have
issues with Flake8 not accepting your choices, reconfigure Flake8 :)

ChrisA

Re: Single line if statement with a continue

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!news.szaf.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: PythonList@DancesWithMice.info (dn)
Newsgroups: comp.lang.python
Subject: Re: Single line if statement with a continue
Date: Thu, 15 Dec 2022 18:24:15 +1300
Organization: DWM
Lines: 32
Message-ID: <mailman.1170.1671081868.20444.python-list@python.org>
References: <af8635f1-30b9-4a0b-b9f8-d81f2c54960an@googlegroups.com>
<bdc418ed-b1cc-7e57-b23d-8765e7a8398e@DancesWithMice.info>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de yRDe3fV/EUWUeKbMxf9dQwKW7PBzkHabK0UB4Jm3j+Bg==
Return-Path: <PythonList@DancesWithMice.info>
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=danceswithmice.info header.i=@danceswithmice.info
header.b=Cdqntjes; dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.002
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '=dn': 0.09;
'from:addr:danceswithmice.info': 0.09; 'from:addr:pythonlist':
0.09; 'occasionally': 0.09; 'simplicity': 0.09; 'continue.': 0.16;
'message-id:@DancesWithMice.info': 0.16; 'received:51.254': 0.16;
'received:51.254.211': 0.16; 'received:51.254.211.219': 0.16;
'received:cloud': 0.16; 'received:rangi.cloud': 0.16;
'subject:continue': 0.16; 'use:': 0.16; 'wrote:': 0.16; 'to:addr
:python-list': 0.20; 'feedback': 0.23; 'run': 0.23; 'seems': 0.26;
'matter.': 0.26; 'header:User-Agent:1': 0.30;
'header:Organization:1': 0.31; 'received:192.168.1': 0.32; 'header
:In-Reply-To:1': 0.34; 'received:192.168': 0.37; 'something':
0.40; 'received:51': 0.64; 'aaron': 0.84; 'cleaner': 0.84
DKIM-Filter: OpenDKIM Filter v2.11.0 vps.rangi.cloud CA8702E90
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=danceswithmice.info;
s=staff; t=1671081866;
bh=C/0RrLHQTuR6qWORKCYV7ht/dK8M1moa0bP+ctOdtMQ=;
h=Date:Subject:To:References:From:In-Reply-To:From;
b=CdqntjeszANZOpBlUbTYTneUwg+tb4Pp1SLRby0aeqfviykWd31Iei0/Q57FOrYNr
T8sHzmXaLIkslF1sszHjrUwAy+wLNA98qVbNmIGZ9w3duDzzDPdq6D/FBsxLv9fA+R
81icFM1iEE7jBvga2eUO1MOp6Vuw9bpk+CKJ0ISRF4v16txJy+NMAu/CTmI0dECiSQ
96WCDk6cHpYOYQgrsEnHlguOXG5jlIjqCnTnPTGvq2YJTvVtFOUoJ/vbWfqp1Cy1Ru
oxMWGBrctAqzntLWrlaWaHSzUuB1jL2b7tyQtOHNaEcJA5dAL8HbwVs6ZehvBPt4FX
rtX/kHNx7tFGg==
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.5.1
Content-Language: en-GB
In-Reply-To: <af8635f1-30b9-4a0b-b9f8-d81f2c54960an@googlegroups.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: <bdc418ed-b1cc-7e57-b23d-8765e7a8398e@DancesWithMice.info>
X-Mailman-Original-References: <af8635f1-30b9-4a0b-b9f8-d81f2c54960an@googlegroups.com>
 by: dn - Thu, 15 Dec 2022 05:24 UTC

On 15/12/2022 07.53, Aaron P wrote:
> I occasionally run across something like:
>
> for idx, thing in enumerate(things):
> if idx == 103:
> continue
> do_something_with(thing)
>
> It seems more succinct and cleaner to use:
>
> if idx == 103: continue.
>
> Of course this would be considered an anti-pattern, and Flake8 will complain.
>
> Any opinions, or feedback on the matter.

These aged-eyes prefer the second line and indentation.

However, another alternative (given simplicity of example):

for ...
if idx != 103:
do_something ...

Which could, in-turn, be boiled-down to a 'one-liner'.

--
Regards,
=dn

Re: Single line if statement with a continue

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: list1@tompassin.net (Thomas Passin)
Newsgroups: comp.lang.python
Subject: Re: Single line if statement with a continue
Date: Thu, 15 Dec 2022 00:06:43 -0500
Lines: 51
Message-ID: <mailman.1171.1671081943.20444.python-list@python.org>
References: <af8635f1-30b9-4a0b-b9f8-d81f2c54960an@googlegroups.com>
<CAPTjJmp7itCdQQ76UQttWg_A8f5Y=NHnSBe_t_BFWXiQEP0nUw@mail.gmail.com>
<1ad0365c-486c-1305-4e65-6b1bcf035b0a@tompassin.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de rQL8YhJeOcoykJuaqHM/DwVJWZR40zuJJwuUqzPKfUbg==
Return-Path: <list1@tompassin.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=tompassin.net header.i=@tompassin.net header.b=MepPnYRI;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.006
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'project,': 0.03; '2022':
0.05; 'usage': 0.05; 'okay': 0.07; 'angelico': 0.09; 'example.':
0.09; 'occasionally': 0.09; 'chrisa': 0.16; 'continue.': 0.16;
'guide,': 0.16; 'pylint': 0.16; 'received:10.0.0': 0.16;
'received:64.90': 0.16; 'received:64.90.62': 0.16;
'received:64.90.62.162': 0.16; 'received:dreamhost.com': 0.16;
'something.': 0.16; 'statements.': 0.16; 'subject:continue': 0.16;
'use:': 0.16; 'wrote:': 0.16; 'larger': 0.17; 'says': 0.17;
'code.': 0.17; 'pm,': 0.19; 'thu,': 0.19; 'to:addr:python-list':
0.20; 'feedback': 0.23; 'run': 0.23; 'seems': 0.26; 'matter.':
0.26; 'chris': 0.28; 'wrong': 0.28; 'header:User-Agent:1': 0.30;
'dec': 0.31; 'guidelines.': 0.32; 'personally': 0.32; 'point,':
0.32; 'received:10.0': 0.32; 'received:mailchannels.net': 0.32;
'received:relay.mailchannels.net': 0.32; 'there': 0.33; 'someone':
0.34; 'same': 0.34; 'header:In-Reply-To:1': 0.34; 'people': 0.36;
'guide': 0.37; "it's": 0.37; 'put': 0.38; 'read': 0.38; 'single':
0.39; 'use': 0.39; 'something': 0.40; 'follow': 0.62; 'involved':
0.63; 'clear': 0.64; 'your': 0.64; 'body': 0.67; 'generally':
0.67; 'header:Received:6': 0.67; 'received:64': 0.67; 'right':
0.68; 'accepting': 0.75; '....': 0.76; '10:': 0.84; 'aaron': 0.84;
'cleaner': 0.84; "else's": 0.84; 'tend': 0.91; 'line,': 0.93
X-Sender-Id: dreamhost|x-authsender|tpassin@tompassin.net
ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1671080805; a=rsa-sha256;
cv=none;
b=7VZyow2t4X7SNc/WswzPzrZICOuZ6KzTM7MArs1yhXABNN2lNYddfqt81yCBx9+J1jsDk8
ngnRLqG3O8enM82FnZ981K8rgFhsc9xBgHw1RvcH9ceSApWfdC1N87QAJx+In2kqq+fgi/
dBVwS+KUu8S7XZ+EkLEps4ADQ9KM5H7OdZ9fSlul8CQXjSGRNYL/tLIT5iBochm7XsZFQ6
rE6YEG8rFp99VNe2Z7KHJOjUgFxMQDtewWDFDNRxiJzK8QTCf3xlwMhKFVGRECYdwpy2An
Qd+XEcDwtvNmEq4xhACPP+qwblMGjZYxlkL9sWzXNluWpbQbZQvAi/upDYt1BA==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed;
d=mailchannels.net; s=arc-2022; t=1671080805;
h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
to:to:cc:mime-version:mime-version:content-type:content-type:
content-transfer-encoding:content-transfer-encoding:
in-reply-to:in-reply-to:references:references:dkim-signature;
bh=noLm5yxo3EJNxI44EIAPTNkdKOBFZiA/lajOv1WoZ8o=;
b=D2rS4gqDmAlKR9KsfMmcJgaecBEfymtoZ9Fx/fP9t/78v2PNSgpWlrJ/mZtEe+lxbcOiGf
R02O/NLv4SDd0twV1P2tH+fiebg0TKBhPQIwfcJsl56gfaUTJ6rqwFsxZeY9nSTyYpVQpY
cG0mbXFbjXeCBULm8bxhtGeTqXyV3BDNgKsy75lb17cdkrPoGTfcHVCbfQp4Qmhnwf+9vO
c+rDFjrBuTn0EUCxEQ6UpXxfOidA3lGNcKlHMraPoBtV7wJAewbajfNXOxE8i/Asnt2vgO
//SlpYlGKYD7cSDQOoziQIAGM+CNWWmYik3PyaT2jdcB/aeK3XD43ar1FNakDw==
ARC-Authentication-Results: i=1; rspamd-d48c5ddb-nj59r;
auth=pass smtp.auth=dreamhost smtp.mailfrom=list1@tompassin.net
X-Sender-Id: dreamhost|x-authsender|tpassin@tompassin.net
X-MC-Relay: Neutral
X-MailChannels-SenderId: dreamhost|x-authsender|tpassin@tompassin.net
X-MailChannels-Auth-Id: dreamhost
X-Reign-Supply: 1b40767b24cd3ad0_1671080805387_4085953857
X-MC-Loop-Signature: 1671080805387:283566672
X-MC-Ingress-Time: 1671080805387
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tompassin.net;
s=dreamhost; t=1671080805;
bh=PbxTzD94NTE8lmQgdDx9Lagz9cyE/AHcD/nesI5ZEUU=;
h=Date:Subject:To:From:Content-Type:Content-Transfer-Encoding;
b=MepPnYRIPK7Im0L21yfeJ3VoWeNyIRvdpUDR13O0xjpe5wfxttxItPqhm5VB0GchO
XCSiXZ7pbR+og25BbJdyf/nvysmK+DAoU2HBSqNJZm4NWgDggNFvdxOKYeAvZ6qZyY
2NjVjHG2jzApOJSHcbpu9VNU5gT00LBpZrDUq34yiAK54lJAKoWZFTe8MF3iuPu6Br
pflBuRXivMKtjNhwlVQLbjR0mqiExfgNgtSUiPU1tFbR8tZjXCugjZFu91dNb/0JwC
LvhtPBf5+Lm2yKGa6Or4A+jL5yoQVzCI9OUXf8Zsf6WrZv44KvtCjApn267Y38e0fB
14HuEvml5nyIQ==
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.5.1
Content-Language: en-US
In-Reply-To: <CAPTjJmp7itCdQQ76UQttWg_A8f5Y=NHnSBe_t_BFWXiQEP0nUw@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: <1ad0365c-486c-1305-4e65-6b1bcf035b0a@tompassin.net>
X-Mailman-Original-References: <af8635f1-30b9-4a0b-b9f8-d81f2c54960an@googlegroups.com>
<CAPTjJmp7itCdQQ76UQttWg_A8f5Y=NHnSBe_t_BFWXiQEP0nUw@mail.gmail.com>
 by: Thomas Passin - Thu, 15 Dec 2022 05:06 UTC

PEP-8, which is Guido's style guide and generally good to follow, does
not completely discourage single-line usage like the example. It's not
clear to me how Chris's example fits into the guidelines.

PEP-8:
"While sometimes it’s okay to put an if/for/while with a small body on
the same line, never do this for multi-clause statements.
....
# Wrong:
if foo == 'blah': do_blah_thing()
for x in lst: total += x
while t < 10: t = delay()
"

If the one-liner were not in a multi-statement block, it would be all
right with PEP-8. OTOH, there is nothing that says one has to fully
comply with PEP-8. I personally tend to use

if test: return

even inside larger blocks. If one is working with other someone else's
project and there is a style guide, it's important to follow that guide
because the other people involved will find it easier to read and
understand your code.

If you are working on your own project, PEP-8 is always a good starting
point, and flake8 and pylint will be happier. That's worth something.

On 12/14/2022 11:35 PM, Chris Angelico wrote:
> On Thu, 15 Dec 2022 at 14:41, Aaron P <transreductionist@gmail.com> wrote:
>>
>> I occasionally run across something like:
>>
>> for idx, thing in enumerate(things):
>> if idx == 103:
>> continue
>> do_something_with(thing)
>>
>> It seems more succinct and cleaner to use:
>>
>> if idx == 103: continue.
>>
>> Of course this would be considered an anti-pattern, and Flake8 will complain.
>>
>> Any opinions, or feedback on the matter.
>
> Nothing at all wrong with writing that on a single line. If you have
> issues with Flake8 not accepting your choices, reconfigure Flake8 :)
>
> ChrisA

Re: Single line if statement with a continue

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: rosuav@gmail.com (Chris Angelico)
Newsgroups: comp.lang.python
Subject: Re: Single line if statement with a continue
Date: Thu, 15 Dec 2022 17:56:08 +1100
Lines: 32
Message-ID: <mailman.1172.1671087381.20444.python-list@python.org>
References: <af8635f1-30b9-4a0b-b9f8-d81f2c54960an@googlegroups.com>
<CAPTjJmp7itCdQQ76UQttWg_A8f5Y=NHnSBe_t_BFWXiQEP0nUw@mail.gmail.com>
<1ad0365c-486c-1305-4e65-6b1bcf035b0a@tompassin.net>
<CAPTjJmqSHxHtH7rOyCeU28C4sT=hnz5xf9VZAqqiD=wuXiVRcQ@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Trace: news.uni-berlin.de H040UIOyYunoTRHXaKYOwgzVOeggOYurCcW42DaoNP2g==
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=dEmGAg/p;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.005
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'this:': 0.03; '2022':
0.05; 'usage': 0.05; 'okay': 0.07; 'pep': 0.07; 'example.': 0.09;
"shouldn't": 0.09; 'that.': 0.15; 'chrisa': 0.16;
'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16;
'statements.': 0.16; 'subject:continue': 0.16; 'wrote:': 0.16;
'thu,': 0.19; 'to:addr:python-list': 0.20; 'saying': 0.25; 'dec':
0.31; 'putting': 0.31; 'guidelines.': 0.32; 'message-
id:@mail.gmail.com': 0.32; 'but': 0.32; 'same': 0.34; 'header:In-
Reply-To:1': 0.34; 'received:google.com': 0.34; 'fine': 0.35;
'from:addr:gmail.com': 0.35; 'guide': 0.37; "it's": 0.37;
'received:209.85': 0.37; 'put': 0.38; 'received:209': 0.39;
'received:209.85.208': 0.39; 'block': 0.39; 'clear': 0.64; 'your':
0.64; 'body': 0.67; 'generally': 0.67; 'right': 0.68; '10:': 0.84;
'line,': 0.93
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=content-transfer-encoding:to:subject:message-id:date:from
:in-reply-to:references:mime-version:from:to:cc:subject:date
:message-id:reply-to;
bh=vw1KAmD39wJmz5VBtCmf2NrW+A2AcI4lP0cxxlWO7VM=;
b=dEmGAg/pg4ZPagozkVPcyk52fkPYM1WB6BUSjIBuK+Wgc26D0t6mKIawoTJrMsR+4f
FDSOeUip7aFdSaCBfnrARY4K4wvya12AhjFrq8XdjRHOvY8Lp3aKONr/3xcJxwj9OwGd
DDGuLv2LkbI3SKgueDYzUf5bboDa4d/Hi+6hGfCPVtqeJRbASnxOk67JuMOQ6f9m1j6g
krR1HstyWP3HVpkbcBPMqMGaHMIdXGD8LYzqPpE55iiKjWMYRO8AqK8KN21mRVr10Thu
zyN7VsGZOIpL2Plt4x3TvDKUdQiJJiGGZ/SM4NRt0KfVYYm7CIoZPcGWFrrgy6nKib3m
ixUA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=content-transfer-encoding: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=vw1KAmD39wJmz5VBtCmf2NrW+A2AcI4lP0cxxlWO7VM=;
b=PW7D1jAVXUoCG57r8w5cSPjOFX9JjLLfr/mjYspPeFy5ZDDivTv1MCKBQdzeoKDnCc
vUTTDt6ZKJILUXgm2IW3BmTYuL0Ej7ZsnsAW1/sHi9aZ1KlM67ZACUeywgQjBEv9KBGK
aZIFncDfKsppEaIjtSIwMktM/wvdG7ReF2Cydm8btjObfq8B7rbJnLpF5w+KKXdHjnQl
RM5e80dKiEXvKEghhin09cwVcgpYHMi7FyyiOscpR49+uZpKxTRv2eUBb/aEuwKJml/X
fFqMWX361tLlzgBixes61LKQMzpxCSvHrymsTfF9hFvcvfWROoLMTttsEaZ5VFa1io15
OtQQ==
X-Gm-Message-State: ANoB5pmaU4UulWLuZ56iJxrweMM+Si9jXI5/XDLXKcWJtyLxdavvepp5
aOR2bRr+4LyKPRRKq1rQySKJeV3zGl98kVsva62+Qn7/0EI=
X-Google-Smtp-Source: AA0mqf73FiHwDVAP/Cx7AxExK/wSo+mAYE7c/ycA9N75Dx3LYvf/0vrghhF6Xmzy9n215PVcaT3fvc/1mWF6qu7zN70=
X-Received: by 2002:a50:eb8f:0:b0:46c:5a22:b00c with SMTP id
y15-20020a50eb8f000000b0046c5a22b00cmr22024744edr.46.1671087380065; Wed, 14
Dec 2022 22:56:20 -0800 (PST)
In-Reply-To: <1ad0365c-486c-1305-4e65-6b1bcf035b0a@tompassin.net>
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: <CAPTjJmqSHxHtH7rOyCeU28C4sT=hnz5xf9VZAqqiD=wuXiVRcQ@mail.gmail.com>
X-Mailman-Original-References: <af8635f1-30b9-4a0b-b9f8-d81f2c54960an@googlegroups.com>
<CAPTjJmp7itCdQQ76UQttWg_A8f5Y=NHnSBe_t_BFWXiQEP0nUw@mail.gmail.com>
<1ad0365c-486c-1305-4e65-6b1bcf035b0a@tompassin.net>
 by: Chris Angelico - Thu, 15 Dec 2022 06:56 UTC

On Thu, 15 Dec 2022 at 16:29, Thomas Passin <list1@tompassin.net> wrote:
>
> PEP-8, which is Guido's style guide and generally good to follow, does
> not completely discourage single-line usage like the example. It's not
> clear to me how Chris's example fits into the guidelines.
>
> PEP-8:
> "While sometimes it’s okay to put an if/for/while with a small body on
> the same line, never do this for multi-clause statements.
> ...
> # Wrong:
> if foo == 'blah': do_blah_thing()
> for x in lst: total += x
> while t < 10: t = delay()
> "
>
> If the one-liner were not in a multi-statement block, it would be all
> right with PEP-8.

Not sure what your point is about it being "in" a multi-statement
block - PEP 8 has nothing to say about that. What it's saying is that
you shouldn't do this:

if foo == 'blah': one(); two(); three()

And I agree; if you're putting more than one statement after your
'if', it's generally clearest to have it on multiple lines. But a
simple "continue" or "break" statement works just fine on the same
line as the if.

ChrisA

RE: Single line if statement with a continue

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: <avi.e.gross@gmail.com>
Newsgroups: comp.lang.python
Subject: RE: Single line if statement with a continue
Date: Thu, 15 Dec 2022 01:58:11 -0500
Lines: 108
Message-ID: <mailman.1173.1671087497.20444.python-list@python.org>
References: <af8635f1-30b9-4a0b-b9f8-d81f2c54960an@googlegroups.com>
<bdc418ed-b1cc-7e57-b23d-8765e7a8398e@DancesWithMice.info>
<005401d91052$98eb2410$cac16c30$@gmail.com>
Mime-Version: 1.0
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de qhmj4PUWWdff1KKogO96rA1NjFZrzvtxUycZKD4j5ubA==
Return-Path: <avi.e.gross@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=VVMIyC84;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.021
X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'this:': 0.03; '2022':
0.05; '=dn': 0.09; 'blank': 0.09; 'occasionally': 0.09;
'readable': 0.09; 'simplicity': 0.09; 'url:mailman': 0.15;
'absence': 0.16; 'applies': 0.16; 'colon': 0.16; 'continue.':
0.16; 'min': 0.16; 'situations.': 0.16; 'subject:continue': 0.16;
'symmetric': 0.16; 'use:': 0.16; 'wrote:': 0.16; 'python': 0.16;
'code.': 0.17; 'message-id:@gmail.com': 0.18; 'to:addr:python-
list': 0.20; 'issue': 0.21; 'language': 0.21; 'languages': 0.22;
'code': 0.23; 'feedback': 0.23; 'lines': 0.23; 'run': 0.23;
'skip:- 10': 0.25; '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; 'matter.': 0.26; 'else':
0.27; 'bit': 0.27; 'done': 0.28; 'error': 0.29; 'code,': 0.31;
'comment': 0.31; 'received:209.85.160': 0.31; 'url-ip:188/8':
0.31; 'program': 0.31; 'python-list': 0.32; 'unless': 0.32;
'there': 0.33; 'someone': 0.34; 'same': 0.34; 'mean': 0.34;
'header:In-Reply-To:1': 0.34; 'received:google.com': 0.34; '"if':
0.35; 'following': 0.35; 'from:addr:gmail.com': 0.35; 'people':
0.36; 'change': 0.36; 'received:209.85': 0.37; 'others': 0.37;
'way': 0.38; 'read': 0.38; 'received:209': 0.39; 'single': 0.39;
'enough': 0.39; 'use': 0.39; 'methods': 0.39; 'received:100':
0.39; 'wants': 0.40; 'both': 0.40; 'something': 0.40; 'want':
0.40; 'should': 0.40; 'inline': 0.61; 'above': 0.62; 'from:':
0.62; 'to:': 0.62; 'once': 0.63; 're:': 0.64; 'your': 0.64;
'parts': 0.65; 'similar': 0.65; 'per': 0.68; 'matter': 0.68;
'fixing': 0.69; 'obvious': 0.69; 'knowing': 0.71; 'low': 0.74;
'easy': 0.74; 'sent:': 0.78; 'thousand': 0.84; 'aaron': 0.84;
'cleaner': 0.84; "else's": 0.84; 'flexible': 0.91
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=content-language:thread-index:content-transfer-encoding
:mime-version:message-id:date:subject:in-reply-to:references:to:from
:from:to:cc:subject:date:message-id:reply-to;
bh=ZFYcEOBy08wTJ9e9EHAOpIdc6TVPNV/A2rmrUU2d+V4=;
b=VVMIyC84nKOi+qmJqFsPcPYylxZ9KkoBC07J67C/r1aOfoXQFg2JLr+2USr2ap9h4k
fM5+7OkxvwNJOhp5+sG99hK6rjMUw88JcEzusGRq1SKCeZOO7gzCTToIivW8SCPCJ0Ip
YeQRdMC6BlKfxkEQFVqpG6P7OEoz3zmq6zJMd18AaZ6WwqHrUxwVauYeGwxj006XwE+/
tFrRbSnvUElh7Rs80lLFOuXxmv+n3n04OJultWAxfL5/dwZajref17F2FFgQkrOX+sPB
Tfhc8EvxrZl01XdP+PKzgPxpklDYvZoG+vKXSvxpdit+K9WLPftVNAfpJ7XTRf3JwESo
cEfA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=content-language:thread-index:content-transfer-encoding
:mime-version:message-id:date:subject:in-reply-to:references:to:from
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
bh=ZFYcEOBy08wTJ9e9EHAOpIdc6TVPNV/A2rmrUU2d+V4=;
b=azEXgLZSx4zx7cUJjJ3TMh9jONxguh1lsjao1HU8eWKHp5PlzjgnsUtCHvozLlQc3W
N195mZZOlPHb/PnvdWpgSHEc0aGMSV/Nj8cdXdnw4eRjxwoOwTdBASD4eTrCBHb3Oayb
T98O6xudDT7DICa6zyk+41gtVVbktViF8MqZkKsX2SSwWJhXes8gDKAiNsi5+afYVvAQ
SAHpVy2VeMTEciEdWgK4TSzL9y5xUMbJy5YpYgX9n4HyAyfxNeoe3bhsgBxFdqiP+Rwr
I5Z29UikztfgKG9aBNmt7G5/6nwABQSPdgy9tTMGfDLoWrXVl9TFjDPaNdeq8k/52BX6
aSqw==
X-Gm-Message-State: ANoB5plExhMNCjOHxrZIXOmpuC59X3wZYRDE5INZCKgf2e0X+pQj7RjB
+ibYzc1HQgYpPBx7qysHfnGMxNk93Xw=
X-Google-Smtp-Source: AA0mqf66khycj/twqpDuikByoNWTIlrwza355/LNht1bVTg72fbjomfe4/FUGVASeco73PZoXFO8aw==
X-Received: by 2002:ac8:5f93:0:b0:3a7:ff9c:3f92 with SMTP id
j19-20020ac85f93000000b003a7ff9c3f92mr41756302qta.22.1671087494121;
Wed, 14 Dec 2022 22:58:14 -0800 (PST)
In-Reply-To: <bdc418ed-b1cc-7e57-b23d-8765e7a8398e@DancesWithMice.info>
X-Mailer: Microsoft Outlook 16.0
Thread-Index: AQJI2jgjpoZjOo45TmZxO3GBPwt80gGXaM5urYIwyJA=
Content-Language: en-us
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: <005401d91052$98eb2410$cac16c30$@gmail.com>
X-Mailman-Original-References: <af8635f1-30b9-4a0b-b9f8-d81f2c54960an@googlegroups.com>
<bdc418ed-b1cc-7e57-b23d-8765e7a8398e@DancesWithMice.info>
 by: <avi.e.gross@gmail.com> - Thu, 15 Dec 2022 06:58 UTC

Unless someone is counting lines of code for some purpose, like number of
error found per thousand lines of code, many short one-liners strike me as
more readable and especially if followed by a blank line so it is a bit
obvious.

Consider a similar issue in many languages that use curly braces and where
they can be skipped in a one liner like "if (condition) statement" rather
than the style some use on multiple lines like:

If (condition) {
Statement
}

Or even:

If (condition)
{
Statement
}

Of course, once you have additional parts following like an "else" that
contains multiple statements, it seems more symmetric to do both parts the
same style.

And in commented code, a one-liner may get long and harder to read as in

If (condition) statement # long comment

Note the above are not python and the absence of a colon is intentional. No
one language is being discussed and some have their own vagaries and
variants such as not knowing if your code is done if you change lines in
ambiguous situations. And note some languages support methods like the ?:
operator or the inline if/else python allows as in this:

min = 5
low = 12
x = low if low >= 12 else min
x 12
low = 3
x = low if low >= 12 else min
result
12

Clearly that is a one-liner that almost has to be a one liner as there is no
obvious easy way to wrap it into multiple lines.

I mean the following works, albeit darned if I know if any of it should be
indented or who wants to read it this way:

x = low \
if \
low >= 12 \
else \
min

x 5

As many have discussed, it is a matter of taste and people should be
flexible enough to program in whatever style others want to see when that
applies such as working in a group project or fixing someone else's code.

-----Original Message-----
From: Python-list <python-list-bounces+avi.e.gross=gmail.com@python.org> On
Behalf Of dn
Sent: Thursday, December 15, 2022 12:24 AM
To: python-list@python.org
Subject: Re: Single line if statement with a continue

On 15/12/2022 07.53, Aaron P wrote:
> I occasionally run across something like:
>
> for idx, thing in enumerate(things):
> if idx == 103:
> continue
> do_something_with(thing)
>
> It seems more succinct and cleaner to use:
>
> if idx == 103: continue.
>
> Of course this would be considered an anti-pattern, and Flake8 will
complain.
>
> Any opinions, or feedback on the matter.

These aged-eyes prefer the second line and indentation.

However, another alternative (given simplicity of example):

for ...
if idx != 103:
do_something ...

Which could, in-turn, be boiled-down to a 'one-liner'.

--
Regards,
=dn
--
https://mail.python.org/mailman/listinfo/python-list

Re: Single line if statement with a continue

<i64r6j-b7c91.ln1@esprimo.zbmc.eu>

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: cl@isbd.net (Chris Green)
Newsgroups: comp.lang.python
Subject: Re: Single line if statement with a continue
Date: Thu, 15 Dec 2022 08:58:26 +0000
Lines: 15
Message-ID: <i64r6j-b7c91.ln1@esprimo.zbmc.eu>
References: <af8635f1-30b9-4a0b-b9f8-d81f2c54960an@googlegroups.com> <CAPTjJmp7itCdQQ76UQttWg_A8f5Y=NHnSBe_t_BFWXiQEP0nUw@mail.gmail.com> <1ad0365c-486c-1305-4e65-6b1bcf035b0a@tompassin.net> <mailman.1171.1671081943.20444.python-list@python.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: individual.net yb1zrGf8UJeMhrZPGidqyAderi+oIlov3/OcE2gV+FhEzC6xw=
X-Orig-Path: not-for-mail
Cancel-Lock: sha1:m8erxQ1IK52OIws6UXOXNd4argQ=
User-Agent: tin/2.6.2-20220130 ("Convalmore") (Linux/5.15.0-56-generic (x86_64))
 by: Chris Green - Thu, 15 Dec 2022 08:58 UTC

Thomas Passin <list1@tompassin.net> wrote:
> I personally tend to use
>
> if test: return
>
> even inside larger blocks.

I always try to avoid multiple returns from functions/methods, as soon
as things get complex it's all to easy to miss clean-up etc.

"No multiple returns" is often found in programming guidelines.

--
Chris Green
·

Re: Single line if statement with a continue

<return-20221215133614@ram.dialup.fu-berlin.de>

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.python
Subject: Re: Single line if statement with a continue
Date: 15 Dec 2022 12:41:54 GMT
Organization: Stefan Ram
Lines: 53
Expires: 1 Sep 2023 11:59:58 GMT
Message-ID: <return-20221215133614@ram.dialup.fu-berlin.de>
References: <af8635f1-30b9-4a0b-b9f8-d81f2c54960an@googlegroups.com> <CAPTjJmp7itCdQQ76UQttWg_A8f5Y=NHnSBe_t_BFWXiQEP0nUw@mail.gmail.com> <1ad0365c-486c-1305-4e65-6b1bcf035b0a@tompassin.net> <mailman.1171.1671081943.20444.python-list@python.org> <i64r6j-b7c91.ln1@esprimo.zbmc.eu>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de bj9OATCSonUv0992VoWMnwLu3lcb2BVBo8siTucfKkRLJt
X-Copyright: (C) Copyright 2022 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE, en-US, it, fr-FR
 by: Stefan Ram - Thu, 15 Dec 2022 12:41 UTC

Chris Green <cl@isbd.net> writes:
>I always try to avoid multiple returns from functions/methods, as soon
>as things get complex it's all to easy to miss clean-up etc.

This "complexity" could also mean that the function has
become too large. In such a case, one could say that the
/size/ of the function is the actual cause of problems
and not multiple returns.

|Fools ignore complexity. Pragmatists suffer it. Some can
|avoid it. Geniuses remove it.
Alan Perlis (1922/1990)

Within a small function, multiple returns are rarely
a problem.

When a function is large, one can apply well-known
refactors. For an example, look at the code in the
first post of the thread

Python script not letting go of files
Date: Tue, 29 Nov 2022 12:52:15 +0000

and then at my reply of

29 Nov 2022 14:44:39 GMT.

>"No multiple returns" is often found in programming guidelines.

I religiously followed that when I did more C programming
than today. Then, I read an article about how the result
pattern makes functions measurably slower. (It should not
with an optimizing compiler, but it did due to those
measurements. Can't find that article now, though.)

"Result pattern" I call writing,

if a:
result = 123
else:
result = 456
return result

, instead of,

if a:
return 123
else
return 456

.

Re: Single line if statement with a continue

<87edt0zucd.fsf@munus.decebal.nl>

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: Cecil@decebal.nl (Cecil Westerhof)
Newsgroups: comp.lang.python
Subject: Re: Single line if statement with a continue
Date: Thu, 15 Dec 2022 14:09:54 +0100
Organization: Decebal Computing
Lines: 22
Message-ID: <87edt0zucd.fsf@munus.decebal.nl>
References: <af8635f1-30b9-4a0b-b9f8-d81f2c54960an@googlegroups.com>
<CAPTjJmp7itCdQQ76UQttWg_A8f5Y=NHnSBe_t_BFWXiQEP0nUw@mail.gmail.com>
<1ad0365c-486c-1305-4e65-6b1bcf035b0a@tompassin.net>
<mailman.1171.1671081943.20444.python-list@python.org>
<i64r6j-b7c91.ln1@esprimo.zbmc.eu>
<return-20221215133614@ram.dialup.fu-berlin.de>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader01.eternal-september.org; posting-host="f64636cf0c9a1b95f67b4dba65ec9bff";
logging-data="3259859"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Aj4PwWFFpzRyhDDHrfdCJMPGdXbKpAXA="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:QUIraZvNlZEfJ3sJDuxI3yC9X0U=
sha1:1Lr3P45x9uv8p444fJgVdn9uM/U=
 by: Cecil Westerhof - Thu, 15 Dec 2022 13:09 UTC

ram@zedat.fu-berlin.de (Stefan Ram) writes:

>>"No multiple returns" is often found in programming guidelines.
>
> I religiously followed that when I did more C programming
> than today. Then, I read an article about how the result
> pattern makes functions measurably slower. (It should not
> with an optimizing compiler, but it did due to those
> measurements. Can't find that article now, though.)

That makes me think about the quote from Edsger W. Dijkstra about the
go to statement:
Please do not fall into the trap of believing that I am terribly
dogmatic about the go to statement. I have the uncomfortable
feeling that others are making a religion out of it, as if the
conceptual problems of programming could be solved by a simple
trick, by a simple form of coding discipline!

--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

RE: Single line if statement with a continue

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: <avi.e.gross@gmail.com>
Newsgroups: comp.lang.python
Subject: RE: Single line if statement with a continue
Date: Thu, 15 Dec 2022 14:05:32 -0500
Lines: 88
Message-ID: <mailman.1178.1671131136.20444.python-list@python.org>
References: <af8635f1-30b9-4a0b-b9f8-d81f2c54960an@googlegroups.com>
<CAPTjJmp7itCdQQ76UQttWg_A8f5Y=NHnSBe_t_BFWXiQEP0nUw@mail.gmail.com>
<1ad0365c-486c-1305-4e65-6b1bcf035b0a@tompassin.net>
<mailman.1171.1671081943.20444.python-list@python.org>
<i64r6j-b7c91.ln1@esprimo.zbmc.eu>
<return-20221215133614@ram.dialup.fu-berlin.de>
<055e01d910b8$349de450$9dd9acf0$@gmail.com>
Mime-Version: 1.0
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de TvU+1XvOyxnQ7OX1PDoP7w5jXQlA2poW/QpgZDgLXEFw==
Return-Path: <avi.e.gross@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=EgICh8Uh;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.019
X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; '2022': 0.05; 'fairly':
0.05; 'thread': 0.05; 'exit': 0.07; 'ram': 0.07; 'cases.': 0.09;
'else:': 0.09; 'rarely': 0.09; 'slides': 0.09; 'smaller': 0.09;
'writes:': 0.09; 'url:mailman': 0.15; 'problem.': 0.15; '(it':
0.16; 'cases,': 0.16; 'complexity.': 0.16; 'large.': 0.16;
'planning.': 0.16; 'subject:continue': 0.16; 'well-known': 0.16;
'problem': 0.16; 'python': 0.16; 'instead': 0.17; "can't": 0.17;
'message-id:@gmail.com': 0.18; 'tue,': 0.19; 'to:addr:python-
list': 0.20; 'issue': 0.21; 'bit.': 0.22; 'returns': 0.22; 'code':
0.23; 'skip:- 10': 0.25; 'url-ip:188.166.95.178/32': 0.25; 'url-
ip:188.166.95/24': 0.25; 'actual': 0.25; 'depends': 0.25;
'url:listinfo': 0.25; 'programming': 0.25; 'url-ip:188.166/16':
0.25; 'pattern': 0.26; 'stefan': 0.26; 'task': 0.26; 'creating':
0.27; 'else': 0.27; 'function': 0.27; 'done': 0.28; 'chris': 0.28;
'example,': 0.28; 'received:209.85.160': 0.31; 'url-ip:188/8':
0.31; 'program': 0.31; 'carefully': 0.32; 'guidelines.': 0.32;
'nature': 0.32; 'python-list': 0.32; 'unless': 0.32; 'but': 0.32;
'there': 0.33; 'script': 0.33; 'same': 0.34; 'mean': 0.34; 'header
:In-Reply-To:1': 0.34; 'received:google.com': 0.34; 'complex':
0.35; 'one.': 0.35; 'from:addr:gmail.com': 0.35; 'files': 0.36;
'functions': 0.36; 'those': 0.36; 'necessarily': 0.37; "it's":
0.37; 'received:209.85': 0.37; 'could': 0.38; 'read': 0.38;
'received:209': 0.39; 'changes': 0.39; 'single': 0.39; 'enough':
0.39; 'date:': 0.39; 'use': 0.39; 'received:100': 0.39; 'alan':
0.40; 'try': 0.40; 'should': 0.40; 'best': 0.61; 'method': 0.61;
'from:': 0.62; 'to:': 0.62; 'seen': 0.62; 'miss': 0.62; 'point.':
0.62; 'everything': 0.63; 'down': 0.64; 're:': 0.64; 'look': 0.65;
'well': 0.65; 'required': 0.65; 'now,': 0.67; 'that,': 0.67;
'decision': 0.68; 'right': 0.68; 'further': 0.69; 'within': 0.69;
'ignore': 0.71; 'article': 0.73; 'easy': 0.74; 'reply': 0.77;
'sent:': 0.78; 'points': 0.84; 'beat': 0.84; 'made,': 0.84;
'optimizing': 0.84; 'statement.': 0.84; 'suffer': 0.91; 'green':
0.96
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=thread-index:content-language:content-transfer-encoding
:mime-version:message-id:date:subject:in-reply-to:references:to:from
:from:to:cc:subject:date:message-id:reply-to;
bh=Ftl+gaVZO7QyOU8IxEQRC0XsayYPUdMNtf9BxULwlak=;
b=EgICh8UhBmyq4mK1GKgEGp33oRVjIIxok86eRy+J9Xgq4dnFADsOEy2YQZUJvBd0yl
aH/CO7ZGu2ncS88IYu5b43h5z/XegwKq7UcFv0dVtzHbfnTrh0mrgxLWuLi+LVdIySZw
LMR3T3mzKzjW90LO0aG5lcVHXqixT43XkZbjnmcuTFLO8cUOnwRfVz2j6e2AAwgQSgkp
/RXgBwLugbe5YejFeKvcG5pPaXwT+eSUtmrLXnfnz1n+cS1fBEpbEtlhWRAytHWQsre/
3k6gBqD3gz6D7LjAJUwSqLXwqbw1cMRjLceK3lZ6YmtlAK5NBz4+brSU0oESi39EmJk8
NOgw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=thread-index:content-language:content-transfer-encoding
:mime-version:message-id:date:subject:in-reply-to:references:to:from
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
bh=Ftl+gaVZO7QyOU8IxEQRC0XsayYPUdMNtf9BxULwlak=;
b=WMpcg9VVSZhO7LXNmfQz/WUjTJJc7gGkknmizbNo3OnSjXuCsJ1wasP+ZXQ64ZJCTg
zUsr8rJen3VBR2dCv2GuQSjlhY/m4iwmkRzN7nFaUwO0/W1FVglvQw9VYucjO4KgfHj3
SnBBCCFl+9Yj/jMn6Kc4mrN7RquZ7P1vhgWMsF4u7aSSpid20TPzyv9bH+XH7m0C2Az/
44cKp5kt51Zw0KU2cQBsENYgfVXhBTamV2T1jrxh7jUTYdwmng3cW0rNu8wa1scdncgT
A/wbhfDbcYMJ8GwkVXZ2nAmhgBRwvNRHEc+n+TMKY+kBO0X4QOdC3wqMKZjsHYUOutLr
GPFw==
X-Gm-Message-State: ANoB5plw2jB8n8Aq6ABjHCshhs/nDuQug/DijiYCVsahUCbVZrXBkY1Y
Ftbro56HAa7SMLrgh8cMuxcAEErRiGA=
X-Google-Smtp-Source: AA0mqf78pShYSJs0nCEL0OIiRAcI6IHrgZz3Qvufy0zWXcqBXmeYHsmQOlPyHmJKFUZwIgJRiYuxNA==
X-Received: by 2002:ac8:660f:0:b0:3a8:e35:258f with SMTP id
c15-20020ac8660f000000b003a80e35258fmr30881296qtp.31.1671131133215;
Thu, 15 Dec 2022 11:05:33 -0800 (PST)
In-Reply-To: <return-20221215133614@ram.dialup.fu-berlin.de>
X-Mailer: Microsoft Outlook 16.0
Content-Language: en-us
Thread-Index: AQJI2jgjpoZjOo45TmZxO3GBPwt80gLd5Qc0AhnEdc0C+O29XgFmVXydAmM9Zs6tMeb6gA==
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: <055e01d910b8$349de450$9dd9acf0$@gmail.com>
X-Mailman-Original-References: <af8635f1-30b9-4a0b-b9f8-d81f2c54960an@googlegroups.com>
<CAPTjJmp7itCdQQ76UQttWg_A8f5Y=NHnSBe_t_BFWXiQEP0nUw@mail.gmail.com>
<1ad0365c-486c-1305-4e65-6b1bcf035b0a@tompassin.net>
<mailman.1171.1671081943.20444.python-list@python.org>
<i64r6j-b7c91.ln1@esprimo.zbmc.eu>
<return-20221215133614@ram.dialup.fu-berlin.de>
 by: <avi.e.gross@gmail.com> - Thu, 15 Dec 2022 19:05 UTC

Multiple returns is not always a problem as it depends on the nature of a
task whether it has complex enough cases.

I have seen code that instead sets Boolean variables when it is ready to
return and everything else keeps checking the variables to skip further
processing so the program then slides down to a single return statement. If
done properly, it boils down to the same result if VERY carefully done but
with lots of sometimes complex IF statements that may be not be updated well
if the logic changes a bit.

In such cases, I vastly prefer clean and unambiguous returns from the
function right at the point where the decision is made, UNLESS the exit is
not always clean as there may be cleanup or finalization of some kind
required that is best done at a single point.

If efficiency is an issue, then clearly a rapid exit may beat one where
processing continues for a while and also often beats a method that involves
creating and calling multiple smaller functions with lots of overhead.

Having said all that, of course, if you can find a fairly simple algorithm
that only returns from one place, use it instead of a convoluted one. The
issue is not necessarily that multiple return points are bad, but that they
are often a symptom of sloppy planning. But for some problems, they fit well
and simplify things.

-----Original Message-----
From: Python-list <python-list-bounces+avi.e.gross=gmail.com@python.org> On
Behalf Of Stefan Ram
Sent: Thursday, December 15, 2022 7:42 AM
To: python-list@python.org
Subject: Re: Single line if statement with a continue

Chris Green <cl@isbd.net> writes:
>I always try to avoid multiple returns from functions/methods, as soon
>as things get complex it's all to easy to miss clean-up etc.

This "complexity" could also mean that the function has
become too large. In such a case, one could say that the
/size/ of the function is the actual cause of problems
and not multiple returns.

|Fools ignore complexity. Pragmatists suffer it. Some can avoid it.
|Geniuses remove it.
Alan Perlis (1922/1990)

Within a small function, multiple returns are rarely
a problem.

When a function is large, one can apply well-known
refactors. For an example, look at the code in the
first post of the thread

Python script not letting go of files
Date: Tue, 29 Nov 2022 12:52:15 +0000

and then at my reply of

29 Nov 2022 14:44:39 GMT.

>"No multiple returns" is often found in programming guidelines.

I religiously followed that when I did more C programming
than today. Then, I read an article about how the result
pattern makes functions measurably slower. (It should not
with an optimizing compiler, but it did due to those
measurements. Can't find that article now, though.)

"Result pattern" I call writing,

if a:
result = 123
else:
result = 456
return result

, instead of,

if a:
return 123
else
return 456

.

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

Re: Single line if statement with a continue

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: gweatherby@uchc.edu (Weatherby,Gerard)
Newsgroups: comp.lang.python
Subject: Re: Single line if statement with a continue
Date: Thu, 15 Dec 2022 19:22:59 +0000
Lines: 119
Message-ID: <mailman.1180.1671132192.20444.python-list@python.org>
References: <af8635f1-30b9-4a0b-b9f8-d81f2c54960an@googlegroups.com>
<CAPTjJmp7itCdQQ76UQttWg_A8f5Y=NHnSBe_t_BFWXiQEP0nUw@mail.gmail.com>
<1ad0365c-486c-1305-4e65-6b1bcf035b0a@tompassin.net>
<mailman.1171.1671081943.20444.python-list@python.org>
<i64r6j-b7c91.ln1@esprimo.zbmc.eu>
<return-20221215133614@ram.dialup.fu-berlin.de>
<055e01d910b8$349de450$9dd9acf0$@gmail.com>
<SA1PR14MB585541E08D29723575C798FDB9E19@SA1PR14MB5855.namprd14.prod.outlook.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable
X-Trace: news.uni-berlin.de EA/RIbi3iDc7Gg2J13rH0g526Htucy/qtDG21kT0S+Qg==
Return-Path: <prvs=03486db407=gweatherby@uchc.edu>
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=uchc.edu header.i=@uchc.edu header.b=DwkEpIpj;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.026
X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; '2022': 0.05; 'fairly':
0.05; 'thread': 0.05; 'exit': 0.07; 'programmer': 0.07; 'ram':
0.07; 'cases.': 0.09; 'else:': 0.09; 'rarely': 0.09;
'received:namprd14.prod.outlook.com': 0.09; 'slides': 0.09;
'smaller': 0.09; 'url-ip:13.107.213.67/32': 0.09; 'url-
ip:13.107.213/24': 0.09; 'url-ip:13.107.246.67/32': 0.09; 'url-
ip:13.107.246/24': 0.09; 'writes:': 0.09; 'url:mailman': 0.15;
'problem.': 0.15; '(it': 0.16; '***': 0.16; 'cases,': 0.16;
'cause.': 0.16; 'complexity.': 0.16; 'confusion': 0.16;
'construct.': 0.16; 'large.': 0.16; 'planning.': 0.16;
'subject:continue': 0.16; 'url:urldefense': 0.16; 'url:v3': 0.16;
'well-known': 0.16; 'problem': 0.16; 'python': 0.16; 'instead':
0.17; "can't": 0.17; 'tue,': 0.19; 'to:addr:python-list': 0.20;
'issue': 0.21; 'bit.': 0.22; 'returns': 0.22; 'code': 0.23;
'to:name:python-list@python.org': 0.24; 'skip:- 10': 0.25;
'actual': 0.25; 'depends': 0.25; 'url:listinfo': 0.25;
'programming': 0.25; 'opening': 0.26; 'pattern': 0.26;
'received:edu': 0.26; 'stefan': 0.26; 'task': 0.26; 'creating':
0.27; 'else': 0.27; 'function': 0.27; 'done': 0.28; 'chris': 0.28;
'email addr:python.org&gt;': 0.28; 'example,': 0.28; 'program':
0.31; 'carefully': 0.32; 'guidelines.': 0.32; 'nature': 0.32;
'python-list': 0.32; 'unless': 0.32; 'but': 0.32; 'there': 0.33;
'script': 0.33; 'same': 0.34; 'mean': 0.34; 'header:In-Reply-
To:1': 0.34; 'complex': 0.35; 'one.': 0.35; 'files': 0.36;
'functions': 0.36; 'header:Received:8': 0.36; 'those': 0.36;
'necessarily': 0.37; 'received:filterd': 0.37;
'received:pps.filterd': 0.37; "it's": 0.37; 'url-ip:13.107/16':
0.38; 'could': 0.38; 'read': 0.38; 'changes': 0.39; 'single':
0.39; 'enough': 0.39; 'date:': 0.39; 'use': 0.39; 'alan': 0.40;
'design,': 0.40; 'try': 0.40; 'should': 0.40;
'charset:windows-1252': 0.60; 'email.': 0.61; 'best': 0.61;
'method': 0.61; 'from:': 0.62; 'to:': 0.62; 'seen': 0.62;
'finally': 0.62; 'miss': 0.62; 'point.': 0.62; 'email
addr:gmail.com': 0.63; 'once': 0.63; 'everything': 0.63; 'down':
0.64; 'full': 0.64; 're:': 0.64; 'saw': 0.65; 'look': 0.65;
'well': 0.65; 'required': 0.65; 'now,': 0.67; 'bad': 0.67; 'url-
ip:104.18/16': 0.67; 'that,': 0.67; 'decision': 0.68; 'right':
0.68; 'further': 0.69;
'received:nam12-bn8-obe.outbound.protection.outlook.com': 0.69;
'url-ip:52.6/16': 0.69; 'within': 0.69; 'ignore': 0.71; 'article':
0.73; 'easy': 0.74; 'causing': 0.75; 'clicking': 0.76; 'poor':
0.76; 'reply': 0.77; 'sent:': 0.78; 'links.': 0.81; 'points':
0.84; 'attention:': 0.84; 'beat': 0.84; 'email name:&lt;python-
list': 0.84; 'handled': 0.84; 'made,': 0.84; 'optimizing': 0.84;
'skip:& 50': 0.84; 'statement.': 0.84; 'suffer': 0.91; 'green':
0.96
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uchc.edu;
h=from : to : subject :
date : message-id : references : in-reply-to : content-type :
mime-version; s=UCHC03162020;
bh=QMlaxGU3YdQC0uUsGspW0dCxEyhPyD2960UUJ6al5fQ=;
b=DwkEpIpjgUzzGV63ZJ4b10MXHvt31ly/dUs+sUCg73BuNZu4AFADDRRWhhkhlQ2nlmPD
4R02onK7Wa/mFQyomURroYtSXzCrQy8kWSU2jWU6J6h3rU39u74U72lYQSyciCtRSvgj
xo/CbXE2SWPge2mRtjNyX38IhYW0po7GDwPKHiMKl69kefPOp3wyLmYX2F42etnQbNOZ
IcWT2CoQxZ7ZVAcTv/zZQesIByOh6nrFdOQDgil1uKuOvRo72Uz1xQ3KNcaf53BpdvbC
nL75l29UHdiOWFS1IotPFdiFCVjVCiL7apov1B5+RR4XqI6yNs0kbc499qyiNm0tVKal Vg==
ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none;
b=OuVWiFJUXZeiReHhpotQdOlVH3787b5QiEh4dAHmd3CPWj1Su4M6vnRivJhCi7AqEAvx8vFu8hSC63sGnLwPCYJu/9Hk/R6fcyQSM4K0XN/ZVyKiIAej7jk5kdGan89GpHnvHWcqDmPbQE1iEd1KCH5VyWu/uDRDU4ADHnth1pDPpR/xB3q07TvfbQhyZYWSsyDttSziD8hApv7vld8I3xQdAPyZhfC3J1YphgmNgIVV2h3YMy/pwBtq0iRWQj4omQyAKRlJfNsU6VPmRcleyvdBGJAnI7NpnZqKCYFKwrpXUcCnLIMInlxP8x5zMjrr+tg9INMWUUxVPm0di6j5Kw==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com;
s=arcselector9901;
h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1;
bh=QMlaxGU3YdQC0uUsGspW0dCxEyhPyD2960UUJ6al5fQ=;
b=n4HaToel3N+plinhXPrKbFObFlD/mBEWoDZFE+HtLtsr3ae0nSgSqWXPWvMNN1hBejk+2r+6IqZ77pA4tQ91SLA4JMSKeJhX+pLQj8JxI2v2mJ7kcgo2pKm7UzuZZwFHtUxJA0Zd5oIISy2LBI4QsXpmpCS7T+QC/EfSC/T6zM1IGduqm7AlKa6YNKAag2lVd04Ss3jm0vfSW6o3tQgTgoAaBIjaVAq8NBhqOAUd1jUbgPV8dyaMjCNInGOTmwSEtOYpFlkgAr4nL/Nmcif9REwCymijplBVZb0DLGOGNJelxRjzW5GRuHWnugodecpzQ4TzTWPBV4G32MdQDK5O/Q==
ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass
smtp.mailfrom=uchc.edu; dmarc=pass action=none header.from=uchc.edu;
dkim=pass header.d=uchc.edu; arc=none
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uchc.onmicrosoft.com;
s=selector2-uchc-onmicrosoft-com;
h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;
bh=QMlaxGU3YdQC0uUsGspW0dCxEyhPyD2960UUJ6al5fQ=;
b=Qr8jkAOGEJENy2M4YsZXk0ELGVxNp84BEDA72KhAdkOhUs33ibnw1Isb8j+s+qSeWLSpfh6wTb2PE/ID/dxtK7N7EbocfMajpdo6namJwEwl4X3TOwVOqzF/VnU/ONNyGIqsKYhdcxPPSZAneoHZfUQdpuNx+UP+vxwQM6AfuTA=
Thread-Topic: Single line if statement with a continue
Thread-Index: AQHZD+1Pf4kMkYFGzEOpB3MOtI3ZAa5uXXUAgAAIu4CAAOQENoAAAAOygAAGVgCAAANX/A==
In-Reply-To: <055e01d910b8$349de450$9dd9acf0$@gmail.com>
Accept-Language: en-US
Content-Language: en-US
X-MS-Has-Attach:
X-MS-TNEF-Correlator:
x-ms-publictraffictype: Email
x-ms-traffictypediagnostic: SA1PR14MB5855:EE_|BY5PR14MB3672:EE_
x-ms-office365-filtering-correlation-id: 04f613d8-e198-4095-f773-08daded1c703
x-ms-exchange-senderadcheck: 1
x-ms-exchange-antispam-relay: 0
x-microsoft-antispam: BCL:0;
x-microsoft-antispam-message-info: zEKqI3BuLtDzUf7WFX7+7MoQTeauwpbRJCCgI+kB9qubmvMoSrJ0gk18HEvKm5Caz86XDLjgYWmLx1wgIDskYHVhFLdQ33sYhqAjqBN0iCzQueaL+t//95gRGTFV+wNw6FoSs1fJQzEYtIzQdgHUIy3pPwiGRzLEDt1j4HIKqDbtilkX/9Rjlu6/9SHVvAEmnRkJixdlvT62iL4O1i8q5W/0HkoYiopOCDQZlYspAkAVJ065fFvU2bajQjBvGqFcPa3EPnf9YNpUU4gddjhtl6zeJd9vQoqJEmbAsnFlUrvzHthQvZG4Bg5inbRS0poUIZaBQMBs74Mi/ZOynNbvXugBSpW2INxRjcbYOqqZ14698s/gc05DYCwXu1Ibae/r0p4LvHebEjcdUPTlsWjjGdjmWEQE7A7CX/p/areJCCSsvnuyZgqy4EK3zXuvwYhT+HEK+22GGrfv2ILVSIXeWPn824/CSTuk5uDNukByEvFrLNh//CS8Ydyi17GzbaEpXlkGbTKOXu4R6PeeXGMmQjqhnq2QXaeEgADiaH9MRo8rml7H+6CWsJZ9SixxnEMRJeUIbVpdBB3PlcPuSFAyyrtlFzKFAgXQ/XQSRm6Dr6BZMn20rrQ3H53i+08ltybmkFWJW3gkubnP8Aa+Mq/xJ8WvMYTHp/XpcH/ErKvrAHgH7LcdnscH2RPOA6A60IbPZFPsTm3SN0nPV6EZtTWlXHABPb3P4X8qNrfrRFPtcKo=
x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:;
IPV:NLI; SFV:NSPM; H:SA1PR14MB5855.namprd14.prod.outlook.com; PTR:; CAT:NONE;
SFS:(13230022)(4636009)(376002)(366004)(346002)(396003)(39860400002)(136003)(451199015)(52536014)(41300700001)(110136005)(966005)(38070700005)(2906002)(8936002)(5660300002)(7696005)(26005)(55016003)(186003)(75432002)(6506007)(9686003)(166002)(41320700001)(53546011)(83380400001)(38100700002)(786003)(66476007)(66556008)(91956017)(64756008)(8676002)(478600001)(71200400001)(66446008)(33656002)(316002)(66946007)(76116006)(86362001)(122000001);
DIR:OUT; SFP:1101;
x-ms-exchange-antispam-messagedata-chunkcount: 1
x-ms-exchange-antispam-messagedata-0: 82Cz6hPLkZhOMeygJn/Nrhyu9+9UBX9TfX+jdLdfIP2gaVJtmQ1k09h2
M+YyMq/yWY3DeYUQzl54XQkmdPgRqDdYIUH0EJqHZeoAW/lx0hIxdOrR
YWeYKit4ztE3Dv5ITBuKKRgzjwCSSzvIupuJ9CkfwrXNqd87cRS6GL+D
bZm85iAX+M4UowjFS4JqDQULGyHoARLKNqbyZkWqPYo687cmcsyN+W07
JWNf7dyXkxjwQbQFZ8QorecBXssUcCB67tCOPJD+7tikiaqJEeUNCfO5
K/o1j7enh85AZdBr6tytmI+mImt7Z+NXBOidiS8vB4I2dFM7EplCO7oF
1qX6vppaTBOnQxAzs/TFuqYVcyf85nsBwH3aq8yrX5eXrO5O8deExh7I
KDgxgoUY3GxfYd6mzSLMCRjUCo5p2EHtROtPiG90VES5AtscI3hb7XWa
FgCq7N+iItN9JpVOFGQAzvG2A2P5htPcZ+9woYapNaUqDcrlu0yAikXi
+GOjhXIfaFyeSMI/PO31ItP/d6dBpgPXeHa0hVlM4YDmo7kVZuHzgupf
hfwTYgUogxU69E6iitYPoKk7p84lmLj8J9yyd7oy80m1Hqezc+a2Sn0c
uyq6TXjTn6y1FiRnu9dE+Z81W58ccwhr/xoD5EtTox78RyEJTjP71BiF
Jei8Ahu4/4JHweVhlcWcfMV9sJQQjNj11iCXQixdcyJ5c0lf8t3Jrtd5
FfE9rDgRty+E/d8kCWkcsTDaucXkGaIeVXOJmCT/PdaQRAVhXbiYJPN5
hdeP31vghJaNvH0F/qyRJdfiS1t4R0q10LLdWpz271Rt3wCio+RpsQ/C
T32y/hMs7vGZEcE66KRnjkcgCQw0RF64Wb7zvKJ6cwhzD8YNyWQ7fZO+
Fb1fvF8W3K3WUpdLp2Cc0xjU1hC9V8Mgmjd2vBXJGhtIFdDpzx9nfNl9
tS+kVG2NyZpsMRLI8LPnlICzudUx+5Fe60vvh7nv48CMBhgMv6acdlq0
9JUOsij5KF9m1syMoDUcp/2hg2m7XmPW8nQ4AAXBOkCbMTSWAa/XKwIz
wgdUenDzB5WlzNNUhPzVP+9XgwsJT0Q5HuUZWOa8VM+VfvzNAEDvZqjR
oPDuJeT+h4EobuMd07I5zjhmUofVuVmzu27vuonW+UEcMpP+R5QrKS3t
1Poh9/AdICHvzLzPOGyR8nDH7HCT7bDE0cY2CFfJyUAIiHICt4cXMJPQ
SsgKJwqo5birqVqnpq19tIhW4Ua53GJhLnlgdsepdP6g4wtHGTkGcSLM
raTQyAsepw5Vwk2lSyMLBCpdmfrk+YYS72BLLlT756M0KsOW4fZZlG6W
B5C7cdMOBnmdPvCGzsgJznvyGA++FbWLVwR595gN2oyZBMAovTK2eLeI
+Kee2tOsOBRw4rx972uLM+OuSqB1qWaCc8CxrNgEhRnC6VPcq9P+BGyH
cIvPTBYCUkDjaZu1e6jq47dZ+iuujb/P/pJXM41WFoJWiG6SOg0SZPPu
wInusTTwPdN06VG4XB31Mwi+cgwq0GCDjvXFcLVTnJdg/b43GBVaqNCZ
RX0ife4ZNxVOKNPqtx1gixaT7C+6xc7XiW2UswZF1cT+FKXHsEaJaQ
==
X-MS-Exchange-CrossTenant-AuthAs: Internal
X-MS-Exchange-CrossTenant-AuthSource: SA1PR14MB5855.namprd14.prod.outlook.com
X-MS-Exchange-CrossTenant-Network-Message-Id: 04f613d8-e198-4095-f773-08daded1c703
X-MS-Exchange-CrossTenant-originalarrivaltime: 15 Dec 2022 19:22:59.4178 (UTC)
X-MS-Exchange-CrossTenant-fromentityheader: Hosted
X-MS-Exchange-CrossTenant-id: 5c82d83a-818a-4c16-b540-ded2344a7ad3
X-MS-Exchange-CrossTenant-mailboxtype: HOSTED
X-MS-Exchange-CrossTenant-userprincipalname: e6XA+dPf3raCCMEHjRwLWx7W3Hz37m3UVshzt4bQFB1sVHcNbECPXqaGTL5coW6E17yFaqCCc4mSilhivRw9Iw==
X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR14MB3672
X-Proofpoint-GUID: YjBWZ00BBa0lGX8fV6WQaAG01l3lm30x
X-Proofpoint-ORIG-GUID: YjBWZ00BBa0lGX8fV6WQaAG01l3lm30x
X-Proofpoint-Virus-Version: vendor=baseguard
engine=ICAP:2.0.205,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1
definitions=2022-12-15_11,2022-12-15_02,2022-06-22_01
X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0
spamscore=0 phishscore=0
suspectscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 malwarescore=0
priorityscore=1501 lowpriorityscore=0 impostorscore=0 bulkscore=0
clxscore=1011 classifier=spam adjust=0 reason=mlx scancount=1
engine=8.12.0-2212070000 definitions=main-2212150162
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: <SA1PR14MB585541E08D29723575C798FDB9E19@SA1PR14MB5855.namprd14.prod.outlook.com>
X-Mailman-Original-References: <af8635f1-30b9-4a0b-b9f8-d81f2c54960an@googlegroups.com>
<CAPTjJmp7itCdQQ76UQttWg_A8f5Y=NHnSBe_t_BFWXiQEP0nUw@mail.gmail.com>
<1ad0365c-486c-1305-4e65-6b1bcf035b0a@tompassin.net>
<mailman.1171.1671081943.20444.python-list@python.org>
<i64r6j-b7c91.ln1@esprimo.zbmc.eu>
<return-20221215133614@ram.dialup.fu-berlin.de>
<055e01d910b8$349de450$9dd9acf0$@gmail.com>
 by: Weatherby,Gerard - Thu, 15 Dec 2022 19:22 UTC

I once saw a C function full of GOTOs which jumped to the return state at the bottom of the functions because the programmer had learned that “multiple returns are a bad idea.”

I totally agree multiple returns causing confusion is a symptom of poor design, not a cause.

Required cleanup is easily handled by the try / finally construct.

From: Python-list <python-list-bounces+gweatherby=uchc.edu@python.org> on behalf of avi.e.gross@gmail.com <avi.e.gross@gmail.com>
Date: Thursday, December 15, 2022 at 2:07 PM
To: python-list@python.org <python-list@python.org>
Subject: RE: Single line if statement with a continue
*** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. ***

Multiple returns is not always a problem as it depends on the nature of a
task whether it has complex enough cases.

I have seen code that instead sets Boolean variables when it is ready to
return and everything else keeps checking the variables to skip further
processing so the program then slides down to a single return statement. If
done properly, it boils down to the same result if VERY carefully done but
with lots of sometimes complex IF statements that may be not be updated well
if the logic changes a bit.

In such cases, I vastly prefer clean and unambiguous returns from the
function right at the point where the decision is made, UNLESS the exit is
not always clean as there may be cleanup or finalization of some kind
required that is best done at a single point.

If efficiency is an issue, then clearly a rapid exit may beat one where
processing continues for a while and also often beats a method that involves
creating and calling multiple smaller functions with lots of overhead.

Having said all that, of course, if you can find a fairly simple algorithm
that only returns from one place, use it instead of a convoluted one. The
issue is not necessarily that multiple return points are bad, but that they
are often a symptom of sloppy planning. But for some problems, they fit well
and simplify things.

-----Original Message-----
From: Python-list <python-list-bounces+avi.e.gross=gmail.com@python.org> On
Behalf Of Stefan Ram
Sent: Thursday, December 15, 2022 7:42 AM
To: python-list@python.org
Subject: Re: Single line if statement with a continue

Chris Green <cl@isbd.net> writes:
>I always try to avoid multiple returns from functions/methods, as soon
>as things get complex it's all to easy to miss clean-up etc.

This "complexity" could also mean that the function has
become too large. In such a case, one could say that the
/size/ of the function is the actual cause of problems
and not multiple returns.

|Fools ignore complexity. Pragmatists suffer it. Some can avoid it.
|Geniuses remove it.
Alan Perlis (1922/1990)

Within a small function, multiple returns are rarely
a problem.

When a function is large, one can apply well-known
refactors. For an example, look at the code in the
first post of the thread

Python script not letting go of files
Date: Tue, 29 Nov 2022 12:52:15 +0000

and then at my reply of

29 Nov 2022 14:44:39 GMT.

>"No multiple returns" is often found in programming guidelines.

I religiously followed that when I did more C programming
than today. Then, I read an article about how the result
pattern makes functions measurably slower. (It should not
with an optimizing compiler, but it did due to those
measurements. Can't find that article now, though.)

"Result pattern" I call writing,

if a:
result = 123
else:
result = 456
return result

, instead of,

if a:
return 123
else
return 456

.

--
https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!lVeLOl91qPUjowC1ch_u353upn8X-V4rsReaNberWpIXBlBP6CYcDgr_aaMb0ZHoYX4YWO8id1biCn6sW7V6vJM$<https://urldefense.com/v3/__https:/mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!lVeLOl91qPUjowC1ch_u353upn8X-V4rsReaNberWpIXBlBP6CYcDgr_aaMb0ZHoYX4YWO8id1biCn6sW7V6vJM$>

--
https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!lVeLOl91qPUjowC1ch_u353upn8X-V4rsReaNberWpIXBlBP6CYcDgr_aaMb0ZHoYX4YWO8id1biCn6sW7V6vJM$<https://urldefense.com/v3/__https:/mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!lVeLOl91qPUjowC1ch_u353upn8X-V4rsReaNberWpIXBlBP6CYcDgr_aaMb0ZHoYX4YWO8id1biCn6sW7V6vJM$>

Re: Single line if statement with a continue

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: python@mrabarnett.plus.com (MRAB)
Newsgroups: comp.lang.python
Subject: Re: Single line if statement with a continue
Date: Thu, 15 Dec 2022 19:34:28 +0000
Lines: 123
Message-ID: <mailman.1182.1671132870.20444.python-list@python.org>
References: <af8635f1-30b9-4a0b-b9f8-d81f2c54960an@googlegroups.com>
<CAPTjJmp7itCdQQ76UQttWg_A8f5Y=NHnSBe_t_BFWXiQEP0nUw@mail.gmail.com>
<1ad0365c-486c-1305-4e65-6b1bcf035b0a@tompassin.net>
<mailman.1171.1671081943.20444.python-list@python.org>
<i64r6j-b7c91.ln1@esprimo.zbmc.eu>
<return-20221215133614@ram.dialup.fu-berlin.de>
<055e01d910b8$349de450$9dd9acf0$@gmail.com>
<f14535db-bf39-0569-ec59-34677ba4d7f8@mrabarnett.plus.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de w8msWpe1JTSjQONETLIV7A7k2TLq8Qm5o/sOQUZEyheg==
Return-Path: <python@mrabarnett.plus.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=plus.com header.i=@plus.com header.b=MXWwRy3d;
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.005
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; '2022': 0.05; 'fairly':
0.05; 'thread': 0.05; 'exit': 0.07; 'ram': 0.07; 'cases.': 0.09;
'else:': 0.09; 'from:addr:python': 0.09; 'rarely': 0.09;
'received:192.168.1.64': 0.09; 'slides': 0.09; 'smaller': 0.09;
'writes:': 0.09; 'url:mailman': 0.15; 'problem.': 0.15; '(it':
0.16; 'cases,': 0.16; 'complexity.': 0.16; 'excessive': 0.16;
'from:addr:mrabarnett.plus.com': 0.16; 'from:name:mrab': 0.16;
'large.': 0.16; 'message-id:@mrabarnett.plus.com': 0.16;
'planning.': 0.16; 'received:84.93': 0.16; 'received:84.93.230':
0.16; 'received:plus.net': 0.16; 'subject:continue': 0.16; 'well-
known': 0.16; 'wrote:': 0.16; 'problem': 0.16; 'python': 0.16;
'instead': 0.17; "can't": 0.17; 'tue,': 0.19; 'to:addr:python-
list': 0.20; 'issue': 0.21; 'bit.': 0.22; 'returns': 0.22; 'code':
0.23; 'skip:- 10': 0.25; 'url-ip:188.166.95.178/32': 0.25; 'url-
ip:188.166.95/24': 0.25; 'actual': 0.25; 'depends': 0.25;
'url:listinfo': 0.25; 'programming': 0.25; 'url-ip:188.166/16':
0.25; 'pattern': 0.26; 'stefan': 0.26; 'task': 0.26; 'creating':
0.27; 'else': 0.27; 'function': 0.27; 'done': 0.28; 'chris': 0.28;
'example,': 0.28; 'header:User-Agent:1': 0.30; 'url-ip:188/8':
0.31; 'program': 0.31; 'carefully': 0.32; 'guidelines.': 0.32;
'nature': 0.32; 'python-list': 0.32; 'unless': 0.32;
'received:192.168.1': 0.32; 'but': 0.32; 'there': 0.33; 'script':
0.33; 'same': 0.34; 'mean': 0.34; 'header:In-Reply-To:1': 0.34;
'complex': 0.35; 'one.': 0.35; 'files': 0.36; 'functions': 0.36;
'those': 0.36; 'necessarily': 0.37; "it's": 0.37;
'received:192.168': 0.37; 'could': 0.38; 'read': 0.38; 'changes':
0.39; 'single': 0.39; 'enough': 0.39; 'date:': 0.39; 'use': 0.39;
'alan': 0.40; 'try': 0.40; 'should': 0.40; 'best': 0.61; 'method':
0.61; 'from:': 0.62; 'to:': 0.62; 'seen': 0.62; 'miss': 0.62;
'point.': 0.62; 'email addr:gmail.com': 0.63; 'everything': 0.63;
'down': 0.64; 're:': 0.64; 'look': 0.65; 'well': 0.65; 'required':
0.65; 'lead': 0.67; 'now,': 0.67; 'that,': 0.67; 'decision': 0.68;
'right': 0.68; 'further': 0.69; 'within': 0.69; 'ignore': 0.71;
'article': 0.73; 'easy': 0.74; 'reply': 0.77; 'sent:': 0.78;
'points': 0.84; 'beat': 0.84; 'made,': 0.84; 'optimizing': 0.84;
'statement.': 0.84; 'suffer': 0.91; 'green': 0.96
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=plus.com; s=042019;
t=1671132868; bh=q4igxvWoyNEUKMtKmldBPpQE8vblJfY7nL8d1hMm7Qk=;
h=Date:Subject:To:References:From:In-Reply-To;
b=MXWwRy3dp7lltGaMNRLV7mchsGMpj4mO5zQsjECYUKeppMMDrJML+m/UnM5gvpi+C
t25IMkXjzXloDtjdmlK+Bp2V5HfUs9OBfh3HtMD9V+1D2vFz1mbFMCIt7fLMfyqYcI
EsmuDvuKkQAeiwLzsL9WCYdXawrGEqIt9Wp/dkt13/l67UqG/IhwBlLB6fr0QFv0sI
nTFiHVKoSc/jcFyScgajV18qdiDlVazduTvqFPdB7rAwjj4YYLTa3liYtcROmvbmFb
vZGrtaK6HAd9FseA15ZNSEpQLp5u+g2Dz9SrvNP1Cbfp7MWmxLYsT4NWdi2FVPMkQx
M8PnEUnO4jY+A==
X-Clacks-Overhead: "GNU Terry Pratchett"
X-CM-Score: 0.00
X-CNFS-Analysis: v=2.4 cv=Lo2Bd1Rc c=1 sm=1 tr=0 ts=639b76c4
a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17
a=IkcTkHD0fZMA:10 a=pGLkceISAAAA:8 a=8AHkEIZyAAAA:8 a=QO5V5U7tAAAA:8
a=ZsHEgx13sYwzQ6KTFsYA:9 a=QEXdDO2ut3YA:10 a=zEoEZnOxw-JT089L_GTe:22
X-AUTH: mrabarnett@:2500
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.5.1
Content-Language: en-GB
In-Reply-To: <055e01d910b8$349de450$9dd9acf0$@gmail.com>
X-CMAE-Envelope: MS4xfN5DTK57x+m3rte2kZrqdx+gCUaI2x7ULnPdvzmVPUI8Wt1r336gEMeRVJl69kQ4ANUW9YLB4Ophr4O7cLpkqAwN0bLHWd21tH6uOcjagbthYGltClXy
yhlIGs2sTDfAXsdljs2xrzeFk0JBQu6K4XPljpIHLt4NB2iGGvZ13E4JbEFzaxkAE4rUpmlHS2VqkAdx0Io8I8w1IUs0Jcvs93I=
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: <f14535db-bf39-0569-ec59-34677ba4d7f8@mrabarnett.plus.com>
X-Mailman-Original-References: <af8635f1-30b9-4a0b-b9f8-d81f2c54960an@googlegroups.com>
<CAPTjJmp7itCdQQ76UQttWg_A8f5Y=NHnSBe_t_BFWXiQEP0nUw@mail.gmail.com>
<1ad0365c-486c-1305-4e65-6b1bcf035b0a@tompassin.net>
<mailman.1171.1671081943.20444.python-list@python.org>
<i64r6j-b7c91.ln1@esprimo.zbmc.eu>
<return-20221215133614@ram.dialup.fu-berlin.de>
<055e01d910b8$349de450$9dd9acf0$@gmail.com>
 by: MRAB - Thu, 15 Dec 2022 19:34 UTC

On 2022-12-15 19:05, avi.e.gross@gmail.com wrote:
> Multiple returns is not always a problem as it depends on the nature of a
> task whether it has complex enough cases.
>
> I have seen code that instead sets Boolean variables when it is ready to
> return and everything else keeps checking the variables to skip further
> processing so the program then slides down to a single return statement. If
> done properly, it boils down to the same result if VERY carefully done but
> with lots of sometimes complex IF statements that may be not be updated well
> if the logic changes a bit.
>
> In such cases, I vastly prefer clean and unambiguous returns from the
> function right at the point where the decision is made, UNLESS the exit is
> not always clean as there may be cleanup or finalization of some kind
> required that is best done at a single point.
>
A problem with having a single return is that it can lead to excessive
indentation:

if test_1:
...

if test_2:
...

if test_3:
...

return

With multiple returns, however:

if not test_1:
return

...

if not test_2:
return

...

if not test_3:
return

...

return

> If efficiency is an issue, then clearly a rapid exit may beat one where
> processing continues for a while and also often beats a method that involves
> creating and calling multiple smaller functions with lots of overhead.
>
> Having said all that, of course, if you can find a fairly simple algorithm
> that only returns from one place, use it instead of a convoluted one. The
> issue is not necessarily that multiple return points are bad, but that they
> are often a symptom of sloppy planning. But for some problems, they fit well
> and simplify things.
>
> -----Original Message-----
> From: Python-list <python-list-bounces+avi.e.gross=gmail.com@python.org> On
> Behalf Of Stefan Ram
> Sent: Thursday, December 15, 2022 7:42 AM
> To: python-list@python.org
> Subject: Re: Single line if statement with a continue
>
> Chris Green <cl@isbd.net> writes:
>>I always try to avoid multiple returns from functions/methods, as soon
>>as things get complex it's all to easy to miss clean-up etc.
>
> This "complexity" could also mean that the function has
> become too large. In such a case, one could say that the
> /size/ of the function is the actual cause of problems
> and not multiple returns.
>
> |Fools ignore complexity. Pragmatists suffer it. Some can avoid it.
> |Geniuses remove it.
> Alan Perlis (1922/1990)
>
> Within a small function, multiple returns are rarely
> a problem.
>
> When a function is large, one can apply well-known
> refactors. For an example, look at the code in the
> first post of the thread
>
> Python script not letting go of files
> Date: Tue, 29 Nov 2022 12:52:15 +0000
>
> and then at my reply of
>
> 29 Nov 2022 14:44:39 GMT.
>
>>"No multiple returns" is often found in programming guidelines.
>
> I religiously followed that when I did more C programming
> than today. Then, I read an article about how the result
> pattern makes functions measurably slower. (It should not
> with an optimizing compiler, but it did due to those
> measurements. Can't find that article now, though.)
>
> "Result pattern" I call writing,
>
> if a:
> result = 123
> else:
> result = 456
> return result
>
> , instead of,
>
> if a:
> return 123
> else
> return 456
>
> .
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>

Re: Single line if statement with a continue

<refactoring-20221215204803@ram.dialup.fu-berlin.de>

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.python
Subject: Re: Single line if statement with a continue
Date: 15 Dec 2022 19:49:08 GMT
Organization: Stefan Ram
Lines: 24
Expires: 1 Sep 2023 11:59:58 GMT
Message-ID: <refactoring-20221215204803@ram.dialup.fu-berlin.de>
References: <af8635f1-30b9-4a0b-b9f8-d81f2c54960an@googlegroups.com> <CAPTjJmp7itCdQQ76UQttWg_A8f5Y=NHnSBe_t_BFWXiQEP0nUw@mail.gmail.com> <1ad0365c-486c-1305-4e65-6b1bcf035b0a@tompassin.net> <mailman.1171.1671081943.20444.python-list@python.org> <i64r6j-b7c91.ln1@esprimo.zbmc.eu> <return-20221215133614@ram.dialup.fu-berlin.de> <055e01d910b8$349de450$9dd9acf0$@gmail.com> <f14535db-bf39-0569-ec59-34677ba4d7f8@mrabarnett.plus.com> <mailman.1182.1671132870.20444.python-list@python.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de q+ScSIARW+fiMqmU+229TgDVfW8aCbjWomYfzPityKK3YN
X-Copyright: (C) Copyright 2022 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE, en-US, it, fr-FR
 by: Stefan Ram - Thu, 15 Dec 2022 19:49 UTC

MRAB <python@mrabarnett.plus.com> writes:
>A problem with having a single return is that it can lead to excessive
>indentation:
> if test_1:
> ...
> if test_2:
> ...
> if test_3:
> ...
> return

Refactoring is fun with executable code, no fun with vague
pseudo code. Therefore, I have chosen not to refactor the
vague pseudo code from above. Instead I'd like to recommend
to look at the code in the first post of the thread

Python script not letting go of files
Date: Tue, 29 Nov 2022 12:52:15 +0000

and then at my reply of

29 Nov 2022 14:44:39 GMT.

Re: Single line if statement with a continue

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: list1@tompassin.net (Thomas Passin)
Newsgroups: comp.lang.python
Subject: Re: Single line if statement with a continue
Date: Thu, 15 Dec 2022 14:56:03 -0500
Lines: 16
Message-ID: <mailman.1185.1671136542.20444.python-list@python.org>
References: <af8635f1-30b9-4a0b-b9f8-d81f2c54960an@googlegroups.com>
<CAPTjJmp7itCdQQ76UQttWg_A8f5Y=NHnSBe_t_BFWXiQEP0nUw@mail.gmail.com>
<1ad0365c-486c-1305-4e65-6b1bcf035b0a@tompassin.net>
<mailman.1171.1671081943.20444.python-list@python.org>
<i64r6j-b7c91.ln1@esprimo.zbmc.eu>
<a497c7ce-32fe-4c3e-21c7-8eb429b6e71e@tompassin.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de 5nCItMBRtJ3AK7vLO7/bHA+F3Kxa/KqHbtKH0BNdawAw==
Return-Path: <list1@tompassin.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=tompassin.net header.i=@tompassin.net header.b=gIr0LyG/;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.051
X-Spam-Evidence: '*H*': 0.90; '*S*': 0.00; 'received:23.83.212': 0.09;
'received:elm.relay.mailchannels.net': 0.09; 'received:10.0.0':
0.16; 'received:64.90': 0.16; 'received:64.90.62': 0.16;
'received:64.90.62.162': 0.16; 'received:dreamhost.com': 0.16;
'subject:continue': 0.16; 'wrote:': 0.16; 'larger': 0.17; 'uses':
0.19; 'to:addr:python-list': 0.20; 'returns': 0.22; 'programming':
0.25; 'chris': 0.28; 'header:User-Agent:1': 0.30; 'am,': 0.31;
'guidelines.': 0.32; 'personally': 0.32; 'received:10.0': 0.32;
'received:mailchannels.net': 0.32;
'received:relay.mailchannels.net': 0.32; 'header:In-Reply-To:1':
0.34; '"if': 0.35; 'complex': 0.35; 'yes,': 0.35; "it's": 0.37;
'branch': 0.39; 'use': 0.39; 'try': 0.40; 'miss': 0.62;
'header:Received:6': 0.67; 'received:64': 0.67; 'easy': 0.74;
'return,': 0.91; 'tend': 0.91; 'green': 0.96
X-Sender-Id: dreamhost|x-authsender|tpassin@tompassin.net
ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1671134165; a=rsa-sha256;
cv=none;
b=IkMHxoj2rKCq4GhlqOTryLSJITK9ec01qPd5qDaF0dOYoCMqciqgVaXPkRgnMeiVrm720A
G3/KpWMmiys5hpuWtVWK4jAWwe2vrV2pGkCX4EgzEh+LKX4QinNY6d8gD8uUdK5OikVWp5
zPWWnqvk0SM0yr1MITLLzhkX1gjYFVtD7F08H6EghOgbRXAB4idf9jhjRGPQIKvlgY0xAD
GldMCxrFz7yBpmNAeV/y2K/y7d7H4yeU2fJDYllIvRQCW1ftCPNgzWASt4n+ylH/T6As/K
Nx07LjlhQ0LntOWp2UoSQpS+UOmtR4uZpL3S49fPlSEjp/LFnUtJ4503bUM/gA==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed;
d=mailchannels.net; s=arc-2022; t=1671134165;
h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
to:to:cc:mime-version:mime-version:content-type:content-type:
content-transfer-encoding:content-transfer-encoding:
in-reply-to:in-reply-to:references:references:dkim-signature;
bh=ubGkKj3F1iJxVqES2+4dZu3uOJ3NDPLKD6p/ITyrpiE=;
b=P3CY7m0TzLU8tR8lNbAD9ci6N5JogVKpiKfA+m7QB+6ae0EmGJtXXvmLi6UsvT3JQR+UgS
ATgkcxmyDLMgkR/115XXXVxOMFNhzXx3i/MgYcfGg9Y3QcVV73Qrr3Fi9XA7WcRgnRBAW1
WrwjT6UzDrnWGzCUi2f77ux9NYX4sDNu4A8DszMFwihzukGcwPBsQutIkc8iM58USU7eTX
Xr8JepSIUwOkaxchobD2hep3V94fdwvQ1SVmFb8I7e1O9Mv70cTqliJo3rIq4Y3+4rTqi5
Bw9behkx029fGMCZDwPlFY+Hi2B4ft4GDPyflq9bEf4RWcZmpZgwvXaZjO1ydw==
ARC-Authentication-Results: i=1; rspamd-747d4f8b9f-2hvk8;
auth=pass smtp.auth=dreamhost smtp.mailfrom=list1@tompassin.net
X-Sender-Id: dreamhost|x-authsender|tpassin@tompassin.net
X-MC-Relay: Neutral
X-MailChannels-SenderId: dreamhost|x-authsender|tpassin@tompassin.net
X-MailChannels-Auth-Id: dreamhost
X-Harmony-Stupid: 684a8d1869fe9225_1671134165391_456222204
X-MC-Loop-Signature: 1671134165391:3401110515
X-MC-Ingress-Time: 1671134165391
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tompassin.net;
s=dreamhost; t=1671134165;
bh=ubGkKj3F1iJxVqES2+4dZu3uOJ3NDPLKD6p/ITyrpiE=;
h=Date:From:Subject:To:Content-Type:Content-Transfer-Encoding;
b=gIr0LyG/84NT406yo+5iuphn07F6EFA3ni9AYjj97vjgX+cJOxqnRDD21SBVMrPWZ
GRA79XuCBzahqo+JjmtchrTu2ztHB9IX9N3FooepBISjhHGaQw8zHH3xa4anELrWQn
ritPxDUTc0wReHEpbMX839QG3PB4fvO3EUHTxljKEOk8XZRJ1zm5XnVP3+oqs18JAl
VkHOp/AnEpZ+Bp2ETlyvHpbp+isoGypTIp0mgESIxQtwKh2YSmJUxFq3CnTnRHqdFC
Vqv37f2oRsZk/Zsej6+3FcAdxf+IRP32N7BhXjnSQ1hbB0Rb+qbOLt1jNj0S+SF/bj
Mx4SMCukKJ2gA==
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.5.1
Content-Language: en-US
In-Reply-To: <i64r6j-b7c91.ln1@esprimo.zbmc.eu>
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: <a497c7ce-32fe-4c3e-21c7-8eb429b6e71e@tompassin.net>
X-Mailman-Original-References: <af8635f1-30b9-4a0b-b9f8-d81f2c54960an@googlegroups.com>
<CAPTjJmp7itCdQQ76UQttWg_A8f5Y=NHnSBe_t_BFWXiQEP0nUw@mail.gmail.com>
<1ad0365c-486c-1305-4e65-6b1bcf035b0a@tompassin.net>
<mailman.1171.1671081943.20444.python-list@python.org>
<i64r6j-b7c91.ln1@esprimo.zbmc.eu>
 by: Thomas Passin - Thu, 15 Dec 2022 19:56 UTC

On 12/15/2022 3:58 AM, Chris Green wrote:
> Thomas Passin <list1@tompassin.net> wrote:
>> I personally tend to use
>>
>> if test: return
>>
>> even inside larger blocks.
>
> I always try to avoid multiple returns from functions/methods, as soon
> as things get complex it's all to easy to miss clean-up etc.
>
> "No multiple returns" is often found in programming guidelines.

Yes, or alternatively, "If any branch uses a return, they all should."

Re: Single line if statement with a continue

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: grant.b.edwards@gmail.com (Grant Edwards)
Newsgroups: comp.lang.python
Subject: Re: Single line if statement with a continue
Date: Thu, 15 Dec 2022 13:34:54 -0800 (PST)
Lines: 44
Message-ID: <mailman.1186.1671140098.20444.python-list@python.org>
References: <af8635f1-30b9-4a0b-b9f8-d81f2c54960an@googlegroups.com>
<CAPTjJmp7itCdQQ76UQttWg_A8f5Y=NHnSBe_t_BFWXiQEP0nUw@mail.gmail.com>
<1ad0365c-486c-1305-4e65-6b1bcf035b0a@tompassin.net>
<mailman.1171.1671081943.20444.python-list@python.org>
<i64r6j-b7c91.ln1@esprimo.zbmc.eu>
<return-20221215133614@ram.dialup.fu-berlin.de>
<055e01d910b8$349de450$9dd9acf0$@gmail.com>
<f14535db-bf39-0569-ec59-34677ba4d7f8@mrabarnett.plus.com>
<639b92fe.050a0220.26f48.0575@mx.google.com>
X-Trace: news.uni-berlin.de gvCXodoSV1MN+xlU5fS6sgVYPElDHaE0gToKryopAuEA==
Return-Path: <grant.b.edwards@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=pfNaPi6u;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.033
X-Spam-Evidence: '*H*': 0.93; '*S*': 0.00; 'exit': 0.07;
'received:209.85.166.179': 0.09; '8-10': 0.16; 'error"': 0.16;
'excessive': 0.16; 'from:addr:grant.b.edwards': 0.16;
'from:name:grant edwards': 0.16; 'nested': 0.16;
'subject:continue': 0.16; 'wrote:': 0.16; 'problem': 0.16;
'instead': 0.17; 'to:addr:python-list': 0.20; 'code': 0.23;
'error': 0.29; 'header:User-Agent:1': 0.30; 'deep': 0.31;
'received:google.com': 0.34; 'received:209.85.166': 0.35;
'from:addr:gmail.com': 0.35; 'received:209.85': 0.37;
'received:209': 0.39; 'single': 0.39; 'something': 0.40;
'provide': 0.60; 'lead': 0.67; 'important.': 0.69; 'conditions':
0.70; 'front': 0.70; 'hundreds': 0.75; 'accordingly.': 0.76
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=to:user-agent:references:subject:from:date:message-id:from:to:cc
:subject:date:message-id:reply-to;
bh=jtB2PfCuzXF3zm9Q70ozCL/eZo7gV5/CRWpAOlWWaK0=;
b=pfNaPi6u6firB1P6EF5H/pXinDBFbm04RjCxB9MRwYrVK8fTc93Ns8HZBUc05Rt/Z0
aRK49XT9mhpARRzKa+qT78qfrTDvBFUwJJEn5/nJCya9lL34gxFXHi1caysi0kcQy8mC
KpixkUN0Vgl9uFufiWGcBfRTueCT/cLFkJkxZp91Eles2wUv6BDffvQAdv+y1Ew0MGx0
O9nXCD1xQeJIo8slDiPaLKfTE7C0Mshk6xARAFQ+szemzA0uGbJwnTFfH1wKFyitU9rQ
VvvKtQJGRhlqizgSZU2HlEJeeyr0Fye7kCWweNT40XNSRelEKMkAMFRJuyHdIdbYky9v
XGNw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=to:user-agent:references:subject:from:date:message-id
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
bh=jtB2PfCuzXF3zm9Q70ozCL/eZo7gV5/CRWpAOlWWaK0=;
b=kXXVA0maBhKvPOaDeLyj11Yu3GECfyvSfvLTJyQM9wqCDIYXGAlRq8C4o1VnA3q/KO
bxArIpEJgXhjSZ6pltA/yxx9StLgYHTvEpuw5KTbEb5AFRGed7P2GakkNSlMDIl9jO+P
CANuUWJ3CBtmIl8bdSJPsCfsYB2fAmnbrW8Dbpo6qIXTilRAraXhIEpUHHRcYJCJPmeO
fMl/MrjVs3AUIQ0okUH5KeEN9gZhkSwYo1spewoQVYPdptx3mye/rUhJZsv/EZQYc9n7
PhrafAhyEauL34HznXeMl/pWP32VNT5/jh7zWnvhUJThV5L1mzvbrmtemFHBqxmupwit
obpA==
X-Gm-Message-State: ANoB5pkLPPabTMEOpyoW73N4464mgGHNDEM6z5xYSbd6Y9DWi317jLPt
YTSz0/V9v4WP5W7xJeSf66myMHeKr7c=
X-Google-Smtp-Source: AA0mqf7nhMBjplxnDd03AsiC/3hzhRGtCDOYlqqwIuSX1nz+N5flhtjykIWmXw1qw9EPfyT2dbBzow==
X-Received: by 2002:a92:b747:0:b0:303:8cfe:7169 with SMTP id
c7-20020a92b747000000b003038cfe7169mr16680798ilm.12.1671140095366;
Thu, 15 Dec 2022 13:34:55 -0800 (PST)
User-Agent: slrn/1.0.3 (Linux)
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: <639b92fe.050a0220.26f48.0575@mx.google.com>
X-Mailman-Original-References: <af8635f1-30b9-4a0b-b9f8-d81f2c54960an@googlegroups.com>
<CAPTjJmp7itCdQQ76UQttWg_A8f5Y=NHnSBe_t_BFWXiQEP0nUw@mail.gmail.com>
<1ad0365c-486c-1305-4e65-6b1bcf035b0a@tompassin.net>
<mailman.1171.1671081943.20444.python-list@python.org>
<i64r6j-b7c91.ln1@esprimo.zbmc.eu>
<return-20221215133614@ram.dialup.fu-berlin.de>
<055e01d910b8$349de450$9dd9acf0$@gmail.com>
<f14535db-bf39-0569-ec59-34677ba4d7f8@mrabarnett.plus.com>
 by: Grant Edwards - Thu, 15 Dec 2022 21:34 UTC

On 2022-12-15, MRAB <python@mrabarnett.plus.com> wrote:

> A problem with having a single return is that it can lead to excessive
> indentation:
>
> if test_1:
> ...
>
> if test_2:
> ...
>
> if test_3:
> ...
>
> return

I sometimes have to work on code like that with bocks nested 8-10
levels deep spread out over hundreds of lines. The first thing I do is
convert it to something like the code below. Check for error
conditions up front and exit accordingly.

When working in C, a "goto error" or "goto done" instead of "return"
can provide a "single return" if that's deemed important.

>
> With multiple returns, however:
>
> if not test_1:
> return
>
> ...
>
> if not test_2:
> return
>
> ...
>
> if not test_3:
> return
>
> ...
>
> return

Re: Single line if statement with a continue

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!aioe.org!news.mb-net.net!open-news-network.org!news.mind.de!bolzen.all.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: rob.cliffe@btinternet.com (Rob Cliffe)
Newsgroups: comp.lang.python
Subject: Re: Single line if statement with a continue
Date: Thu, 15 Dec 2022 13:30:39 +0000
Lines: 26
Message-ID: <mailman.1204.1671304467.20444.python-list@python.org>
References: <af8635f1-30b9-4a0b-b9f8-d81f2c54960an@googlegroups.com>
<CAPTjJmp7itCdQQ76UQttWg_A8f5Y=NHnSBe_t_BFWXiQEP0nUw@mail.gmail.com>
<4f21e136-dbec-3aed-60e2-c3908bebce71@btinternet.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de +nqQSTrIsLfbFf6StYi5bgLQGoM/IYASCTDC13Rm3AJg==
Return-Path: <rob.cliffe@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=MxziwJFh;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.093
X-Spam-Evidence: '*H*': 0.82; '*S*': 0.00; '2022': 0.05; 'angelico':
0.09; 'occasionally': 0.09; 'chrisa': 0.16; 'continue.': 0.16;
'subject:continue': 0.16; 'use:': 0.16; 'wrote:': 0.16; 'python':
0.16; 'thu,': 0.19; 'to:addr:python-list': 0.20; 'run': 0.23;
'seems': 0.26; 'done': 0.28; 'chris': 0.28; 'wrong': 0.28; 'header
:User-Agent:1': 0.30; 'code,': 0.31; 'dec': 0.31;
'received:192.168.1': 0.32; "i'm": 0.33; 'header:In-Reply-To:1':
0.34; 'others': 0.37; 'received:192.168': 0.37; 'quite': 0.39;
'single': 0.39; 'received:213': 0.40; 'wishes': 0.40; 'something':
0.40; 'best': 0.61; 'skip:b 20': 0.63; 'clear': 0.64; 'your':
0.64; 'plus': 0.73; 'accepting': 0.75; 'breaking': 0.78; 'aaron':
0.84; 'cleaner': 0.84; 'rob': 0.84; 'glad': 0.86
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=btinternet.com;
s=btmx201904; t=1671111039;
bh=sQJq/78PdeKblJHglfF6OeY6JYveAYYw8qSVSxY5RSU=;
h=Message-ID:Date:MIME-Version:Subject:To:References:From:In-Reply-To;
b=MxziwJFhwzb7y7e6JRhAZ5GiB/3c36SPDGcR6VWZim2M0dZWKKUhzfiN1MKbsXvDBU6DXwO+TgxmZe17euYSBNfjlb+1KNZv52i6hBDlOsHTTt3xiixyEK8aYdWvtMvYe3fAaqNKGIq9MTjH98mLs6O1y5oifcN+qLeYE7PkGoQjN8gx4CAO0oNvnKoTV569ozsVYlWT2gNeBPEIMRyOg+dMMFnvrhkCTuBOaUax6RcVOV+8X3LDNDz5EATiZaiqYO6fxxbRnXu/6ToebKkLKPuiwFPuHACUy+TSezfSFJ5uLPHrUL+YdoBdAIQKX6g+GU8QRIxh9jENGbHiqS4AnQ==
Authentication-Results: btinternet.com;
auth=pass (PLAIN) smtp.auth=rob.cliffe@btinternet.com;
bimi=skipped
X-SNCR-Rigid: 613A901C4711B0B4
X-Originating-IP: [81.154.249.119]
X-OWM-Source-IP: 81.154.249.119 (GB)
X-OWM-Env-Sender: rob.cliffe@btinternet.com
X-VadeSecure-score: verdict=clean score=0/300, class=clean
X-RazorGate-Vade: gggruggvucftvghtrhhoucdtuddrgedvhedrfeehgdehvdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemuceutffkvffkuffjvffgnffgvefqofdpqfgfvfenuceurghilhhouhhtmecufedtudenucenucfjughrpefkffggfgfuvfhfhfgjtgfgsehtkeertddtfeejnecuhfhrohhmpeftohgsucevlhhifhhfvgcuoehrohgsrdgtlhhifhhfvgessghtihhnthgvrhhnvghtrdgtohhmqeenucggtffrrghtthgvrhhnpedvteduhfetgfevgeeiffelledvuefgieekveevhedutefgveeijeeftdetvedtgeenucfkphepkedurdduheegrddvgeelrdduudelnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehhvghloheplgduledvrdduieekrddurddvtdegngdpihhnvghtpeekuddrudehgedrvdegledrudduledpmhgrihhlfhhrohhmpehrohgsrdgtlhhifhhfvgessghtihhnthgvrhhnvghtrdgtohhmpdhnsggprhgtphhtthhopedupdhrtghpthhtohepphihthhhohhnqdhlihhsthesphihthhhohhnrdhorhhg
X-RazorGate-Vade-Verdict: clean 0
X-RazorGate-Vade-Classification: clean
X-SNCR-hdrdom: btinternet.com
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.5.1
Content-Language: en-GB
In-Reply-To: <CAPTjJmp7itCdQQ76UQttWg_A8f5Y=NHnSBe_t_BFWXiQEP0nUw@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: <4f21e136-dbec-3aed-60e2-c3908bebce71@btinternet.com>
X-Mailman-Original-References: <af8635f1-30b9-4a0b-b9f8-d81f2c54960an@googlegroups.com>
<CAPTjJmp7itCdQQ76UQttWg_A8f5Y=NHnSBe_t_BFWXiQEP0nUw@mail.gmail.com>
 by: Rob Cliffe - Thu, 15 Dec 2022 13:30 UTC

On 15/12/2022 04:35, Chris Angelico wrote:
> On Thu, 15 Dec 2022 at 14:41, Aaron P <transreductionist@gmail.com> wrote:
>> I occasionally run across something like:
>>
>> for idx, thing in enumerate(things):
>> if idx == 103:
>> continue
>> do_something_with(thing)
>>
>> It seems more succinct and cleaner to use:
>>
>> if idx == 103: continue.
>>
>>
>> Nothing at all wrong with writing that on a single line. If you have
>> issues with Flake8 not accepting your choices, reconfigure Flake8 :)
>>
>> ChrisA
I'm so glad that Chris and others say this.  It (i.e. if plus
break/continue/return on a single line) is something I have quite often
done in my own code, albeit with a feeling of guilt that I was breaking
a Python taboo.  Now I will do it with a clear conscience. 😁
Best wishes
Rob Cliffe

Re: Single line if statement with a continue

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: abdullahnafees23@gmail.com (Abdullah Nafees)
Newsgroups: comp.lang.python
Subject: Re: Single line if statement with a continue
Date: Sun, 18 Dec 2022 00:22:42 +0500
Lines: 37
Message-ID: <mailman.1207.1671306977.20444.python-list@python.org>
References: <af8635f1-30b9-4a0b-b9f8-d81f2c54960an@googlegroups.com>
<CAPTjJmp7itCdQQ76UQttWg_A8f5Y=NHnSBe_t_BFWXiQEP0nUw@mail.gmail.com>
<4f21e136-dbec-3aed-60e2-c3908bebce71@btinternet.com>
<CA+SQCwuzscCroLkn9HhgaVMGVTPuQ5gPLuGFpLCFLJ9fPUX_8A@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Trace: news.uni-berlin.de AfNXrH31Zo0fSF1uHSOxtA+EnvY+A0rK7lydYVkc9EeA==
Return-Path: <abdullahnafees23@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=HKdjvfJ3;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.005
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; '2022': 0.05; 'thread':
0.05; 'sun,': 0.07; 'angelico': 0.09; 'cc:addr:python-list': 0.09;
'email addr:python.org>': 0.09; 'mentor': 0.09; 'occasionally':
0.09; '&gt;': 0.14; 'cc:no real name:2**0': 0.14; 'url:mailman':
0.15; '&gt;&gt;\xc2\xa0': 0.16; '2022,': 0.16; 'chrisa': 0.16;
'continue.': 0.16; 'received:209.85.218': 0.16;
'subject:continue': 0.16; 'use:': 0.16; 'wrote:': 0.16; 'python':
0.16; 'thu,': 0.19; 'cc:addr:python.org': 0.20; 'run': 0.23; 'url-
ip:188.166.95.178/32': 0.25; 'url-ip:188.166.95/24': 0.25;
'url:listinfo': 0.25; 'cc:2**0': 0.25; 'url-ip:188.166/16': 0.25;
'seems': 0.26; 'done': 0.28; 'chris': 0.28; 'email
addr:python.org&gt;': 0.28; 'wrong': 0.28; 'code,': 0.31; 'dec':
0.31; 'url-ip:188/8': 0.31; 'message-id:@mail.gmail.com': 0.32;
"i'm": 0.33; 'header:In-Reply-To:1': 0.34; 'received:google.com':
0.34; 'from:addr:gmail.com': 0.35; 'received:209.85': 0.37;
'others': 0.37; 'this.': 0.37; 'received:209': 0.39; 'quite':
0.39; 'single': 0.39; 'much.': 0.39; 'wishes': 0.40; 'something':
0.40; 'best': 0.61; 'skip:b 20': 0.63; 'clear': 0.64; 'your':
0.64; 'earlier': 0.67; 'plus': 0.73; 'accepting': 0.75;
'breaking': 0.78; 'aaron': 0.84; 'cleaner': 0.84; 'email name:&lt
;python-list': 0.84; 'rob': 0.84; 'glad': 0.86
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=cc:to:subject:message-id:date:from:in-reply-to:references
:mime-version:from:to:cc:subject:date:message-id:reply-to;
bh=7QuoRo0a7eQu0BPiHkzc6mSWRjlFTT6O0/pB2IHLjMw=;
b=HKdjvfJ3fCrDiTZmK4/QldYCzjEFlUSjmzj2pMFfp1uqplnXG5rouKY7nv6cDoL2Sp
1r2vVytQJX7Aog8yEN1Sje0JjYf7zuSHSdDQkPzsNfad+2LVqohOPh2Be8gXoLu7XeJn
4uSBhlIg9OQuiW/TTKGoGK3bEMFCtX6IXWDwReSPMMEmIM/4SnfmVZ0c479CVlHsubxJ
qqpiIpwvELvcj30oeW5cNhVA/DqiRF5A0J9tib4x4yGjGqippY1rdNZLysCNHxq+RuqC
bCGV9sqZiCzuFBM3CY6mmcPa2/3fCHC7BgDVaANnMhH6IjbOENvdQTJhPLIbJBY4BCyh
0plQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=cc: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=7QuoRo0a7eQu0BPiHkzc6mSWRjlFTT6O0/pB2IHLjMw=;
b=F+Coxrss629Epqflkc2Qeogcu3CGuwpmJl8in4nuZZfIBStEKh6vAQocxThLAyz/UL
Tk2x0NjN/ziKqiBdrR8c9bZKhWlAbVvjMPbwbCLnAIsqeWfqhidMq0wIGsTNg3CNnf4v
na1blYq1gV97R8suYXYGlVJIfqJZO/rsxKCyWWW6WKQGiCmonVPu3AfoObtmOGxwQJJW
tzO87pdeanBqjYdh3DAIE7vnNZUfFTCscv8Iwgm4oOgyw1jU3yuHAFYwLeWafLafzuyi
Hz1cVA0k15IPjrGHPmgPONyBDK/1GqRRtMTk8e8QsYuCh4RriJiEJdO0/+RwIDpvpah3
jEvQ==
X-Gm-Message-State: ANoB5pnF2z28qS3nS74tN5BNn56EGSz6bQOEwutZU+xdM9RdpS5tNwkw
yXQpbvzR/Akn2rz4Q24/JRmhsiqWUNO3ReNrgmM=
X-Google-Smtp-Source: AA0mqf4Y9dRoUCFc87vTLDysDfqUsyUEYrs4YsNPj1j6xEa1V8SATaIn+rwqcNEqTy+AXQzXs3tSuqASw1auMozAr6E=
X-Received: by 2002:a17:907:a607:b0:7c1:9a67:dc50 with SMTP id
vt7-20020a170907a60700b007c19a67dc50mr1966663ejc.385.1671304973587; Sat, 17
Dec 2022 11:22:53 -0800 (PST)
In-Reply-To: <4f21e136-dbec-3aed-60e2-c3908bebce71@btinternet.com>
X-Mailman-Approved-At: Sat, 17 Dec 2022 14:56:16 -0500
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: <CA+SQCwuzscCroLkn9HhgaVMGVTPuQ5gPLuGFpLCFLJ9fPUX_8A@mail.gmail.com>
X-Mailman-Original-References: <af8635f1-30b9-4a0b-b9f8-d81f2c54960an@googlegroups.com>
<CAPTjJmp7itCdQQ76UQttWg_A8f5Y=NHnSBe_t_BFWXiQEP0nUw@mail.gmail.com>
<4f21e136-dbec-3aed-60e2-c3908bebce71@btinternet.com>
 by: Abdullah Nafees - Sat, 17 Dec 2022 19:22 UTC

Just wanted to say that a silent reader like me learnt more about PEP-8
solely from this thread than my mentor at work or any other course I have
taken earlier this year. Thank you so much.

On Sun, 18 Dec 2022, 00:16 Rob Cliffe via Python-list, <
python-list@python.org> wrote:

>
>
> On 15/12/2022 04:35, Chris Angelico wrote:
> > On Thu, 15 Dec 2022 at 14:41, Aaron P <transreductionist@gmail.com>
> wrote:
> >> I occasionally run across something like:
> >>
> >> for idx, thing in enumerate(things):
> >> if idx == 103:
> >> continue
> >> do_something_with(thing)
> >>
> >> It seems more succinct and cleaner to use:
> >>
> >> if idx == 103: continue.
> >>
> >>
> >> Nothing at all wrong with writing that on a single line. If you have
> >> issues with Flake8 not accepting your choices, reconfigure Flake8 :)
> >>
> >> ChrisA
> I'm so glad that Chris and others say this. It (i.e. if plus
> break/continue/return on a single line) is something I have quite often
> done in my own code, albeit with a feeling of guilt that I was breaking
> a Python taboo. Now I will do it with a clear conscience. 😁
> Best wishes
> Rob Cliffe
> --
> https://mail.python.org/mailman/listinfo/python-list
>

Re: Single line if statement with a continue

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!fu-berlin.de!uni-berlin.de!not-for-mail
From: PythonList@DancesWithMice.info (dn)
Newsgroups: comp.lang.python
Subject: Re: Single line if statement with a continue
Date: Sun, 18 Dec 2022 10:59:14 +1300
Organization: DWM
Lines: 35
Message-ID: <mailman.1215.1671314364.20444.python-list@python.org>
References: <af8635f1-30b9-4a0b-b9f8-d81f2c54960an@googlegroups.com>
<CAPTjJmp7itCdQQ76UQttWg_A8f5Y=NHnSBe_t_BFWXiQEP0nUw@mail.gmail.com>
<4f21e136-dbec-3aed-60e2-c3908bebce71@btinternet.com>
<9db24918-e924-3c0a-9a84-d513c6efd51d@DancesWithMice.info>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de kIxJjGDpWIFQZ9mCISwMmABBl6JnwYXraEozey9FWu5g==
Return-Path: <PythonList@DancesWithMice.info>
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=danceswithmice.info header.i=@danceswithmice.info
header.b=c9WMment; dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.030
X-Spam-Evidence: '*H*': 0.94; '*S*': 0.00; '2022': 0.05; '=dn': 0.09;
'angelico': 0.09; 'from:addr:danceswithmice.info': 0.09;
'from:addr:pythonlist': 0.09; 'occasionally': 0.09; 'adults':
0.16; 'chrisa': 0.16; 'continue.': 0.16; 'message-
id:@DancesWithMice.info': 0.16; 'received:51.254': 0.16;
'received:51.254.211': 0.16; 'received:51.254.211.219': 0.16;
'received:cloud': 0.16; 'received:rangi.cloud': 0.16;
'subject:continue': 0.16; 'use:': 0.16; 'wrote:': 0.16; 'python':
0.16; 'thu,': 0.19; 'to:addr:python-list': 0.20; 'code': 0.23;
'run': 0.23; 'anyone': 0.25; 'seems': 0.26; 'done': 0.28; '>>>':
0.28; 'chris': 0.28; 'wrong': 0.28; 'header:User-Agent:1': 0.30;
'code,': 0.31; 'dec': 0.31; 'header:Organization:1': 0.31;
"doesn't": 0.32; 'python-list': 0.32; 'received:192.168.1': 0.32;
"i'm": 0.33; 'header:In-Reply-To:1': 0.34; 'others': 0.37;
'received:192.168': 0.37; 'quite': 0.39; 'least': 0.39; 'single':
0.39; 'something': 0.40; 'remember': 0.61; 'skip:\xc2 10': 0.62;
'skip:b 20': 0.63; 'clear': 0.64; 'received:51': 0.64; 'your':
0.64; 'rules': 0.70; 'you.': 0.71; 'plus': 0.73; 'accepting':
0.75; '8bit%:100': 0.76; 'breaking': 0.78; 'aaron': 0.84;
'cleaner': 0.84; 'rob': 0.84; '\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0':
0.84; 'glad': 0.86; 'anxiety': 0.91
DKIM-Filter: OpenDKIM Filter v2.11.0 vps.rangi.cloud ECE434FAD
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=danceswithmice.info;
s=staff; t=1671314362;
bh=9Z65dkDQ4t6h5W2V+d+0BkP0rj7Mh6skNb6JsGrNPx8=;
h=Date:Subject:To:References:From:In-Reply-To:From;
b=c9WMmentrj1EhupDHn3GDNxZa2WgJPC/k+abN4ooldf1YrLzDzE394rVMCIPcR0Am
HbAg9sglHOirr5Uao9/MX0et580LcDbGgjUvciPyVq1efj8DqsgdR5xxAxY+Rq7Kc0
AZEzVjwJuy28VZ+cAdoo3BIRHn1dd2SQ6C2c1DV0RIYHXxKNkhYGoYzXap2OiHVFcy
4KVgP+zIubdNBTMUSgmYVnIVMbeXkFotysG0ojpUI/RrSbHqYOwEjIecbJVU6YemDx
olqm+lZMEuIw6nHyMlPbBhZhrzOcdWjRj2RWZ0nOpQMZd9SWw/WTrkDh+kqkpggUHO
23RfnHk9lGGhQ==
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.6.0
Content-Language: en-GB
In-Reply-To: <4f21e136-dbec-3aed-60e2-c3908bebce71@btinternet.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: <9db24918-e924-3c0a-9a84-d513c6efd51d@DancesWithMice.info>
X-Mailman-Original-References: <af8635f1-30b9-4a0b-b9f8-d81f2c54960an@googlegroups.com>
<CAPTjJmp7itCdQQ76UQttWg_A8f5Y=NHnSBe_t_BFWXiQEP0nUw@mail.gmail.com>
<4f21e136-dbec-3aed-60e2-c3908bebce71@btinternet.com>
 by: dn - Sat, 17 Dec 2022 21:59 UTC

On 16/12/2022 02.30, Rob Cliffe via Python-list wrote:
> On 15/12/2022 04:35, Chris Angelico wrote:
>> On Thu, 15 Dec 2022 at 14:41, Aaron P <transreductionist@gmail.com>
>> wrote:
>>> I occasionally run across something like:
>>>
>>> for idx, thing in enumerate(things):
>>>      if idx == 103:
>>>          continue
>>>      do_something_with(thing)
>>>
>>> It seems more succinct and cleaner to use:
>>>
>>> if idx == 103: continue.
>>>
>>>
>>> Nothing at all wrong with writing that on a single line. If you have
>>> issues with Flake8 not accepting your choices, reconfigure Flake8 :)
>>>
>>> ChrisA
> I'm so glad that Chris and others say this.  It (i.e. if plus
> break/continue/return on a single line) is something I have quite often
> done in my own code, albeit with a feeling of guilt that I was breaking
> a Python taboo.  Now I will do it with a clear conscience. 😁

Anxiety doesn't help anyone - least of all you.

Remember another Python mantra: "we're all adults here"!

(also (compulsory interjection) PEP-008 is not a set of rules for all
Python code - see PEP-008)

--
Regards,
=dn

RE: Single line if statement with a continue

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!3.eu.feeder.erje.net!feeder.erje.net!fu-berlin.de!uni-berlin.de!not-for-mail
From: <avi.e.gross@gmail.com>
Newsgroups: comp.lang.python
Subject: RE: Single line if statement with a continue
Date: Sat, 17 Dec 2022 18:57:47 -0500
Lines: 162
Message-ID: <mailman.1220.1671321471.20444.python-list@python.org>
References: <af8635f1-30b9-4a0b-b9f8-d81f2c54960an@googlegroups.com>
<CAPTjJmp7itCdQQ76UQttWg_A8f5Y=NHnSBe_t_BFWXiQEP0nUw@mail.gmail.com>
<4f21e136-dbec-3aed-60e2-c3908bebce71@btinternet.com>
<006801d91273$5cfffe80$16fffb80$@gmail.com>
Mime-Version: 1.0
Content-Type: text/plain;
charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Trace: news.uni-berlin.de M374U3HC8fDUCrYpG+9s2Qo2i1sqYdvAljQWTvHgA5DA==
Return-Path: <avi.e.gross@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=NSkCF7gu;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.059
X-Spam-Evidence: '*H*': 0.88; '*S*': 0.00; 'comments': 0.03; '2022':
0.05; 'fairly': 0.05; 'angelico': 0.09; 'compiler': 0.09;
'construct': 0.09; 'expression': 0.09; 'fails': 0.09;
'occasionally': 0.09; 'other.': 0.09; 'readable': 0.09; 'smaller':
0.09; 'url:mailman': 0.15; 'memory': 0.15; 'avi': 0.16;
'calculation': 0.16; 'chrisa': 0.16; 'colon': 0.16; 'column':
0.16; 'concentrate': 0.16; 'constant': 0.16; 'continue.': 0.16;
'deprecated,': 0.16; 'indentation': 0.16; 'interpreter': 0.16;
'languages.': 0.16; 'program?': 0.16; 'received:209.85.160.172':
0.16; 'received:mail-qt1-f172.google.com': 0.16; 'reminds': 0.16;
'short-term': 0.16; 'subject:continue': 0.16; 'though:': 0.16;
'use:': 0.16; 'wrote:': 0.16; 'problem': 0.16; 'python': 0.16;
'larger': 0.17; 'values': 0.17; 'probably': 0.17; 'message-
id:@gmail.com': 0.18; 'calls': 0.19; 'it?': 0.19; 'thu,': 0.19;
'to:addr:python-list': 0.20; 'language': 0.21; 'written': 0.22;
'languages': 0.22; 'basically': 0.22; 'maybe': 0.22; 'version':
0.23; 'code': 0.23; 'lines': 0.23; 'run': 0.23; 'skip:- 10': 0.25;
'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; 'anyone': 0.25;
'seems': 0.26; 'else': 0.27; 'bit': 0.27; 'done': 0.28; 'chris':
0.28; 'wrong': 0.28; 'computer': 0.29; 'it,': 0.29; 'attempt':
0.31; 'code,': 0.31; 'approach': 0.31; 'dec': 0.31;
'received:209.85.160': 0.31; 'url-ip:188/8': 0.31; '(as': 0.32;
'context': 0.32; 'python-list': 0.32; 'rapidly': 0.32;
'requiring': 0.32; 'but': 0.32; "i'm": 0.33; 'hold': 0.33; 'same':
0.34; 'mean': 0.34; 'header:In-Reply-To:1': 0.34;
'received:google.com': 0.34; 'trying': 0.35; 'one.': 0.35;
'understood': 0.35; 'words': 0.35; 'following': 0.35;
'from:addr:gmail.com': 0.35; 'in:': 0.64; 'mainly': 0.64; 're:':
0.64; 'schools': 0.64; 'taught': 0.64; 'your': 0.64; 'similar':
0.65; 'well': 0.65; 'less': 0.65; 'earlier': 0.67; 'shows': 0.67;
'back': 0.67; 'generally': 0.67; 'right': 0.68; '"you': 0.69;
'obvious': 0.69; 'perfectly': 0.69; 'sentence': 0.69; 'within':
0.69; 'below': 0.69; 'rules': 0.70; 'care': 0.71; 'future': 0.72;
'free': 0.72; 'plus': 0.73; 'easy': 0.74; 'accepting': 0.75;
'subsequent': 0.76; 'breaking': 0.78; 'sent:': 0.78; 'states':
0.80; 'moment': 0.81; 'aaron': 0.84; 'admit': 0.84; 'cleaner':
0.84; 'discouraged': 0.84; 'eventually': 0.84; 'exceptions': 0.84;
'experiment': 0.84; 'glance': 0.84; 'go,': 0.84; 'here"': 0.84;
'prejudices': 0.84; 'rob': 0.84; 'sentences': 0.84; 'talked':
0.84; 'varies': 0.84; 'glad': 0.86; 'accompanied': 0.91;
'grammar': 0.91; 'laid': 0.91; 'usage.': 0.91; 'width': 0.91;
'editors,': 0.93; 'implied': 0.93; 'legal,': 0.93; 'mind,': 0.93;
'screen,': 0.93
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=thread-index:content-language:content-transfer-encoding
:mime-version:message-id:date:subject:in-reply-to:references:to:from
:from:to:cc:subject:date:message-id:reply-to;
bh=QT0Mt+BQ7s7P2g7nA6NdpaRsAuLRso3j85ubLec384s=;
b=NSkCF7guFAC4nqmLWOhXmlcRu8cDVKoYsH9MOlONZhLW+TrdET3UUSkkqsYMeWPMk1
G9Mkv23ijJ3Eq0lJPtPO8E3DjAt8p5/p92tbet+NJKbwcCx0lWpQhlTK6qgbcMIJ3w1J
Hc9QIt3zVWsxWgSmkketKqg/6HgyB7o65rcdTGQ/fXY0se6EkgiZCdd5kZGYUrDjMja3
/oQXaW9oHiizu+r+zuK0qHU367/sSf/eU0ekPBtgnQcNYNe+VfXitV/TJ0OQipYWRc6a
TbxCzFZWj13Z/DYwjgKzhhe4C5wdtZWkTbx2JwkNVfI2KVoiNcgQRnZvL3VVPO9i2MkK
5Eiw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=thread-index:content-language:content-transfer-encoding
:mime-version:message-id:date:subject:in-reply-to:references:to:from
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
bh=QT0Mt+BQ7s7P2g7nA6NdpaRsAuLRso3j85ubLec384s=;
b=5DJWLLcDm5JaSbtJeeQxPCBp4zwXzrZDxkHlBsAvUFertpP0yhjn7CdmhIk4q68gRN
BS0R9sqYxigIeQVnlCWuN7Ky/79tAdfj0892kLYRCGoxc0JRy6MYHB//H11hFK2mP7aq
LKMt0r5Q3T/FonwjMWvpW1JMzpPut6xisWT1o8i7qFbJjfdVKHtun0twBAOO8ml3xNGn
VCskQoCfbtoabTzcT4cN58Dlk0akEni5mEtMh++T/MtD6WoLAc1IYQbVUlGmWG1xT+tV
nWwbln5B7lou09fkHgft6OTr0rPjvx5PJ7GKhTqUNPKPOhYh/indadp2b/oQthB/PJYX
Z63g==
X-Gm-Message-State: ANoB5pmuf3f4lXxw3w787+7PEU0zkZXRdSPB2Qx+EVUE1xJlTbhRvTRn
Tx+VbbX+a/dwR39WaK7jKa1cHgjsxJw=
X-Google-Smtp-Source: AA0mqf7ERBPOFYxKRZgwN8dRIx6G1wjeh58ca0TUC6Yc3d9wRKOp/UiMwG8E6BSQpvBusVH60ZSgAA==
X-Received: by 2002:ac8:648:0:b0:3a8:11d6:2d0d with SMTP id
e8-20020ac80648000000b003a811d62d0dmr33449556qth.43.1671321468703;
Sat, 17 Dec 2022 15:57:48 -0800 (PST)
In-Reply-To: <4f21e136-dbec-3aed-60e2-c3908bebce71@btinternet.com>
X-Mailer: Microsoft Outlook 16.0
Content-Language: en-us
Thread-Index: AQJI2jgjpoZjOo45TmZxO3GBPwt80gLd5Qc0AIkvxEStd+t1gA==
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: <006801d91273$5cfffe80$16fffb80$@gmail.com>
X-Mailman-Original-References: <af8635f1-30b9-4a0b-b9f8-d81f2c54960an@googlegroups.com>
<CAPTjJmp7itCdQQ76UQttWg_A8f5Y=NHnSBe_t_BFWXiQEP0nUw@mail.gmail.com>
<4f21e136-dbec-3aed-60e2-c3908bebce71@btinternet.com>
 by: <avi.e.gross@gmail.com> - Sat, 17 Dec 2022 23:57 UTC

I happen to be of two schools here.

Is something sort of taboo when using something like a computer language to write a program? What if another language tells you to do it a different way or sort of the opposite? Is it based on the details of the language and implementation or the prejudices of the one trying to make rules?

If a compiler or interpreter HAPPILY (as happy as machines/code get) compiles or interprets your code without errors every time you use it a certain way, then it is not wrong to use it. Of course if it subject to change or already deprecated, ...

If people around you complain they do not like it, then the word "taboo" does apply but you can feel free to re-educate them or move on.

This reminds me too much of people who are taught some grammar such as some part of a sentence requiring a "noun-phrase" and later it explains that a non-phrase can be EITHER a noun accompanied by an assortment of other words that together form a phrase, or just a "noun" or just a "pronoun" or just a "nothing but an implied pronoun".

So which is it? The answer is all of them are legal, at least within bounds. A sentence like "Come over here" is an implied "You come over here" and works best if earlier sentences have laid some context on what is being talked about so the "you" is obvious or will be explained later but perhaps should be discouraged in other circumstances.

So back to computer languages. Many languages using grouping with something like "{...}" often do not care where you break your lines albeit some get touchy about an else statement placed improperly. It is perfectly legal to write:

If (condition) { first; second; third }

The grammar basically states that a "statement" or similar name can be a simple statement or a compound statement and anywhere one can go, within reason, so can the other.

Python has a twist here in that they discourage or outlaw some such things as they use mainly indentation rather than braces. This makes it hard to use multiple lines when the first line is way at the end as the others do not line up. It becomes all or ONE. I mean it allows a simple expression on the same line after the colon and then terminates the construct so a future indented line is seen as an indentation error. An experiment shows the following attempt to line up a second line way over below the first also fails:

if 5 > 3: a = a * 3
b = b * 3

In a constant width font my second line is indented so "b is just below "a" and it fails because the interpreter does not measure the beginning column of the first line as being where the " a = a * 3" starts but at the "if" and that makes reasonable sense. I could imagine another design but since it is not what is done, the multi-line version MUST be done only on subsequent lines indented properly and identically.

So it is not really right or wrong to do one-liners. It is legal and often more readable. But if you ever want to extend your lines to be multi-line, it probably is best to use the multi-line approach regularly.

Still, using many editors, you will rapidly notice something is wrong when adding a line of code and seeing it is indented under the "if".

Is anyone really thrilled to read code in other languages that span so many lines:

If (condition)
{
var1 = 0
}
else
{
var1 = 1
}

It is a great way to get your line-of-code count up but the many briefer versions can be easier to read in one glance up to and including a bit murkier ones like

var1 = (condition) ? 0 : 1

My view is that simple things that fit easily on a screen, and also held all at once in my mind, should be written fairly concisely. I do admit how much I can hold at once varies based on how well I can concentrate at that moment and have met people whose short-term memory for many things is larger or smaller than mine. But generally people can handle simple constructs like we are discussing.

Complicated things and ones that might need changes later should be written very cautiously and in detail including judicious use of comments around and within the code OR consider re-planning it into a less complicated form that calls on other fairly simple functions that can each be decently understood based on naming and usage.

If you have a complicated calculation that eventually assigns values to a1, a2, a3, a4 then a language like Python makes a
One liner easy as in:

If (condition):
a1, a2, a3, a4 = func(args)

But now that four or more lines have been collapsed into one, maybe something like this works too and maybe is a tad more readable with parentheses:

If (condition): (a1, a2, a3, a4) = func(args)

I am not suggesting using something silly like this though:

if(1): (a, b, c, d) = (min(1,2), (1+2)/2, (1*2*2*3)/4, max(1,2))

That is so way beyond a one liner that it is best seen as multiple lines. It may be legal but is best used to obfuscate!

The problem with some RULES is that not only are they not real rules but sometimes have exceptions where they get in the way of getting things done.

- Avi

-----Original Message-----
From: Python-list <python-list-bounces+avi.e.gross=gmail.com@python.org> On Behalf Of Rob Cliffe via Python-list
Sent: Thursday, December 15, 2022 8:31 AM
To: python-list@python.org
Subject: Re: Single line if statement with a continue

On 15/12/2022 04:35, Chris Angelico wrote:
> On Thu, 15 Dec 2022 at 14:41, Aaron P <transreductionist@gmail.com> wrote:
>> I occasionally run across something like:
>>
>> for idx, thing in enumerate(things):
>> if idx == 103:
>> continue
>> do_something_with(thing)
>>
>> It seems more succinct and cleaner to use:
>>
>> if idx == 103: continue.
>>
>>
>> Nothing at all wrong with writing that on a single line. If you have
>> issues with Flake8 not accepting your choices, reconfigure Flake8 :)
>>
>> ChrisA
I'm so glad that Chris and others say this. It (i.e. if plus break/continue/return on a single line) is something I have quite often done in my own code, albeit with a feeling of guilt that I was breaking a Python taboo. Now I will do it with a clear conscience. 😁
Best wishes
Rob Cliffe
--
https://mail.python.org/mailman/listinfo/python-list

Re: Single line if statement with a continue

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!hirsch.in-berlin.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: list1@tompassin.net (Thomas Passin)
Newsgroups: comp.lang.python
Subject: Re: Single line if statement with a continue
Date: Sat, 17 Dec 2022 19:50:42 -0500
Lines: 134
Message-ID: <mailman.1221.1671324649.20444.python-list@python.org>
References: <af8635f1-30b9-4a0b-b9f8-d81f2c54960an@googlegroups.com>
<CAPTjJmp7itCdQQ76UQttWg_A8f5Y=NHnSBe_t_BFWXiQEP0nUw@mail.gmail.com>
<4f21e136-dbec-3aed-60e2-c3908bebce71@btinternet.com>
<006801d91273$5cfffe80$16fffb80$@gmail.com>
<1bd05dac-6689-98a8-6d47-4df6925eba55@tompassin.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de 77RkZBTjhkPvytNeuOnwIw4mIyfV3lXvF5QqUiihjZDA==
Return-Path: <list1@tompassin.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=tompassin.net header.i=@tompassin.net header.b=ZF2bElLe;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.007
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'comments': 0.03; '2022':
0.05; 'fairly': 0.05; 'python:': 0.05; 'angelico': 0.09;
'compiler': 0.09; 'consistency': 0.09; 'construct': 0.09;
'expression': 0.09; 'fails': 0.09; 'imo,': 0.09; 'occasionally':
0.09; 'other.': 0.09; 'readable': 0.09; 'smaller': 0.09;
'url:mailman': 0.15; 'memory': 0.15; 'another.': 0.16;
'assessing': 0.16; 'avi': 0.16; 'calculation': 0.16; 'chrisa':
0.16; 'colon': 0.16; 'column': 0.16; 'concentrate': 0.16;
'constant': 0.16; 'continue.': 0.16; 'deprecated,': 0.16;
'indentation': 0.16; 'interpreter': 0.16; 'languages.': 0.16;
'program?': 0.16; 'received:10.0.0': 0.16; 'received:64.90': 0.16;
'received:64.90.62': 0.16; 'received:64.90.62.162': 0.16;
'received:dreamhost.com': 0.16; 'reminds': 0.16; 'short-term':
0.16; 'subject:continue': 0.16; 'though:': 0.16; 'understand.':
0.16; 'use:': 0.16; 'widely,': 0.16; 'wrote:': 0.16; 'problem':
0.16; 'python': 0.16; 'larger': 0.17; 'says': 0.17; 'values':
0.17; 'probably': 0.17; 'calls': 0.19; 'it?': 0.19; 'pm,': 0.19;
'reduce': 0.19; 'thu,': 0.19; 'to:addr:python-list': 0.20;
'language': 0.21; 'written': 0.22; 'languages': 0.22; 'basically':
0.22; 'maybe': 0.22; 'version': 0.23; 'code': 0.23; 'lines': 0.23;
'run': 0.23; 'skip:- 10': 0.25; 'url-ip:188.166.95.178/32': 0.25;
'url-ip:188.166.95/24': 0.25; 'url:listinfo': 0.25; 'programming':
0.25; 'url-ip:188.166/16': 0.25; 'anyone': 0.25; 'seems': 0.26;
'else': 0.27; 'bit': 0.27; 'done': 0.28; '>>>': 0.28; 'chris':
0.28; 'wrong': 0.28; 'computer': 0.29; 'it,': 0.29; 'header:User-
Agent:1': 0.30; 'attempt': 0.31; 'code,': 0.31; 'approach': 0.31;
'dec': 0.31; 'url-ip:188/8': 0.31; '(as': 0.32; 'context': 0.32;
'python-list': 0.32; 'rapidly': 0.32; 'received:10.0': 0.32;
'received:mailchannels.net': 0.32;
'received:relay.mailchannels.net': 0.32; 'requiring': 0.32;
'unless': 0.32; 'right': 0.68; 'exactly': 0.68; '"you': 0.69;
'clarity': 0.69; 'factor': 0.69; 'obvious': 0.69; 'perfectly':
0.69; 'sentence': 0.69; 'within': 0.69; 'below': 0.69;
'essential': 0.70; 'rules': 0.70; 'care': 0.71; 'future': 0.72;
'free': 0.72; 'plus': 0.73; 'easy': 0.74; 'accepting': 0.75;
'formatting': 0.76; 'subsequent': 0.76; 'breaking': 0.78; 'sent:':
0.78; 'states': 0.80; 'moment': 0.81; 'aaron': 0.84; 'admit':
0.84; 'cleaner': 0.84; 'discouraged': 0.84; 'eventually': 0.84;
'exceptions': 0.84; 'experiment': 0.84; 'glance': 0.84; 'go,':
0.84; 'here"': 0.84; 'prejudices': 0.84; 'rob': 0.84; 'sentences':
0.84; 'talked': 0.84; 'varies': 0.84; 'weird': 0.84; 'glad': 0.86;
'accompanied': 0.91; 'grammar': 0.91; 'laid': 0.91; 'objectives':
0.91; 'usage.': 0.91; 'width': 0.91; 'editors,': 0.93; 'implied':
0.93; 'legal,': 0.93; 'mind,': 0.93; 'screen,': 0.93; 'guides':
0.96
X-Sender-Id: dreamhost|x-authsender|tpassin@tompassin.net
ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1671324644; a=rsa-sha256;
cv=none;
b=ybbQeFb4gCrl1lQI3G+kOBj/GJs4mDmXvWA8UrlV9i7PETU/btSmQ0RtFvusQHhuA4H/sS
53DnSjJLFSuMh8sqrZ5aPZPETKvTzGmTUGs2LxsbBIEU+YRi2CQ7EZreUKmFey9Cj7O/nU
jOS5AOcZDuAKknXX4cZ32W8ekj+qLOae+cV3cOv01KTzH0b3RwuBZGjBaUn4ef3M1srTn9
l062shjOq+41NlKwhMh2Yf4m+0z4GnXHkAged+6UkS9BTcA9n0k0veSZuiFUrmjHtc5iIf
m0VZc2B+nGeYiBq8dNCzk/T261duXoimcVxs5ZMInyisXiPA2zhR8g/R6lo81w==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed;
d=mailchannels.net; s=arc-2022; t=1671324644;
h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
to:to:cc:mime-version:mime-version:content-type:content-type:
content-transfer-encoding:content-transfer-encoding:
in-reply-to:in-reply-to:references:references:dkim-signature;
bh=wmWT3ua7aihK+XPTAhc63LZXldRDv6y6uRpS0s2Xvts=;
b=Z5WMa6NwpSm3EQslnGVh/InIvWAYtQtEtNwIRJ2tLOl7kYYbei2lA+GbnO+4BQNLMjfSei
L2u9DbdPecn/a0FqCRD7y/tZzocU7hdz4bn6nVN4H9H3H6rPoqTdNc6TIdQXMxKk4AD9IM
BllAPq/v2p9pGcg5qxUODAta1ayNdpiqMULVLwD1vK370Bursdpk74BnFOCP2XysmTFkDs
66C4QNm+BQ44eNjlvEvoNgSo0zlbQA0N6mUpixQm79ORVzNTXO5PMSI+3+K8CQomr9FltG
Mw02zCaQFOq4iC/QZ2QDDrDihveskA5o85NK7YxmEw6oCj300Uq/qu+h/8GMyw==
ARC-Authentication-Results: i=1; rspamd-56db58bdfc-46j9f;
auth=pass smtp.auth=dreamhost smtp.mailfrom=list1@tompassin.net
X-Sender-Id: dreamhost|x-authsender|tpassin@tompassin.net
X-MC-Relay: Neutral
X-MailChannels-SenderId: dreamhost|x-authsender|tpassin@tompassin.net
X-MailChannels-Auth-Id: dreamhost
X-Lettuce-Versed: 6743ff5d7caa2020_1671324644491_2157894048
X-MC-Loop-Signature: 1671324644491:2639450096
X-MC-Ingress-Time: 1671324644491
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tompassin.net;
s=dreamhost; t=1671324644;
bh=wmWT3ua7aihK+XPTAhc63LZXldRDv6y6uRpS0s2Xvts=;
h=Date:Subject:To:From:Content-Type:Content-Transfer-Encoding;
b=ZF2bElLeM/vS5ZgHXCxvZJASeMVIbbX6GY209wfFwKlqP6XSdFYaUeelhMnLkSfyj
x7cc6sQ2bs5rll1kyC3OAgt2wGpJpweDU9GeGJij1h6RIZhSfFTCZ13co8ciqhJyn1
Tp58kJnBjiFZCUuo9NpwlTP9mLIYrF4wxRXMdR3cy2VhWn+DZmQhge8DI7DIHybS/X
TQUPAsFw66XeqFvc0HVL1zKe63NCnh6rE6CTQUaEy+GuZe4QvW73kxzd1+aWtJ7xKR
TWLEqHpFIozVSSCBrWuf/3EljegVOoE1czyMdoaYzl/wRb0oG4DK6aj9+5IQ6jGuXc
4ErzP/a1LmG9Q==
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.6.0
Content-Language: en-US
In-Reply-To: <006801d91273$5cfffe80$16fffb80$@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: <1bd05dac-6689-98a8-6d47-4df6925eba55@tompassin.net>
X-Mailman-Original-References: <af8635f1-30b9-4a0b-b9f8-d81f2c54960an@googlegroups.com>
<CAPTjJmp7itCdQQ76UQttWg_A8f5Y=NHnSBe_t_BFWXiQEP0nUw@mail.gmail.com>
<4f21e136-dbec-3aed-60e2-c3908bebce71@btinternet.com>
<006801d91273$5cfffe80$16fffb80$@gmail.com>
 by: Thomas Passin - Sun, 18 Dec 2022 00:50 UTC

>if 5 > 3: a = a * 3
> b = b * 3

That would be a fairly weird construction, neither one thing nor
another. But still, if you really want it that way, this is legal Python:

a = 2; b = 10
if 5 > 3: a = a * 3;\
b = b * 3
print(a, b) # 6 30

On 12/17/2022 6:57 PM, avi.e.gross@gmail.com wrote:
> I happen to be of two schools here.
>
> Is something sort of taboo when using something like a computer language to write a program? What if another language tells you to do it a different way or sort of the opposite? Is it based on the details of the language and implementation or the prejudices of the one trying to make rules?
>
> If a compiler or interpreter HAPPILY (as happy as machines/code get) compiles or interprets your code without errors every time you use it a certain way, then it is not wrong to use it. Of course if it subject to change or already deprecated, ...

That's not the point of using some consistent style. IMO, source code
should be clear, compact, and easy for someone else to understand. That
someone might be you six months from now.

These objectives do not always align. Consistency helps reduce mental
effort by using constructions and formatting in a familiar way -
basically, using a familiar programming idiom. Compactness can help
clarity, unless the code is too terse which can become a hindrance. But
too much verbosity can get in the way of grasping the essential processing.

Personal taste and familiarity also factor into assessing clarity and
compactness.

It's always a balancing act. Style guides can help by providing good
basic idioms. There's no law** that says you *have* to follow them
exactly all the time. But it's helpful when you can. If your own style
guide i is similar to one used widely, so much the better.

**Except at some organizations

> If people around you complain they do not like it, then the word "taboo" does apply but you can feel free to re-educate them or move on.
>
> This reminds me too much of people who are taught some grammar such as some part of a sentence requiring a "noun-phrase" and later it explains that a non-phrase can be EITHER a noun accompanied by an assortment of other words that together form a phrase, or just a "noun" or just a "pronoun" or just a "nothing but an implied pronoun".
>
> So which is it? The answer is all of them are legal, at least within bounds. A sentence like "Come over here" is an implied "You come over here" and works best if earlier sentences have laid some context on what is being talked about so the "you" is obvious or will be explained later but perhaps should be discouraged in other circumstances.
>
> So back to computer languages. Many languages using grouping with something like "{...}" often do not care where you break your lines albeit some get touchy about an else statement placed improperly. It is perfectly legal to write:
>
> If (condition) { first; second; third }
>
> The grammar basically states that a "statement" or similar name can be a simple statement or a compound statement and anywhere one can go, within reason, so can the other.
>
> Python has a twist here in that they discourage or outlaw some such things as they use mainly indentation rather than braces. This makes it hard to use multiple lines when the first line is way at the end as the others do not line up. It becomes all or ONE. I mean it allows a simple expression on the same line after the colon and then terminates the construct so a future indented line is seen as an indentation error. An experiment shows the following attempt to line up a second line way over below the first also fails:
>
> if 5 > 3: a = a * 3
> b = b * 3
>
> In a constant width font my second line is indented so "b is just below "a" and it fails because the interpreter does not measure the beginning column of the first line as being where the " a = a * 3" starts but at the "if" and that makes reasonable sense. I could imagine another design but since it is not what is done, the multi-line version MUST be done only on subsequent lines indented properly and identically.
>
> So it is not really right or wrong to do one-liners. It is legal and often more readable. But if you ever want to extend your lines to be multi-line, it probably is best to use the multi-line approach regularly.
>
> Still, using many editors, you will rapidly notice something is wrong when adding a line of code and seeing it is indented under the "if".
>
> Is anyone really thrilled to read code in other languages that span so many lines:
>
> If (condition)
> {
> var1 = 0
> }
> else
> {
> var1 = 1
> }
>
> It is a great way to get your line-of-code count up but the many briefer versions can be easier to read in one glance up to and including a bit murkier ones like
>
> var1 = (condition) ? 0 : 1
>
> My view is that simple things that fit easily on a screen, and also held all at once in my mind, should be written fairly concisely. I do admit how much I can hold at once varies based on how well I can concentrate at that moment and have met people whose short-term memory for many things is larger or smaller than mine. But generally people can handle simple constructs like we are discussing.
>
> Complicated things and ones that might need changes later should be written very cautiously and in detail including judicious use of comments around and within the code OR consider re-planning it into a less complicated form that calls on other fairly simple functions that can each be decently understood based on naming and usage.
>
> If you have a complicated calculation that eventually assigns values to a1, a2, a3, a4 then a language like Python makes a
> One liner easy as in:
>
> If (condition):
> a1, a2, a3, a4 = func(args)
>
> But now that four or more lines have been collapsed into one, maybe something like this works too and maybe is a tad more readable with parentheses:
>
> If (condition): (a1, a2, a3, a4) = func(args)
>
>
> I am not suggesting using something silly like this though:
>
> if(1): (a, b, c, d) = (min(1,2), (1+2)/2, (1*2*2*3)/4, max(1,2))
>
> That is so way beyond a one liner that it is best seen as multiple lines. It may be legal but is best used to obfuscate!
>
> The problem with some RULES is that not only are they not real rules but sometimes have exceptions where they get in the way of getting things done.
>
> - Avi
>
> -----Original Message-----
> From: Python-list <python-list-bounces+avi.e.gross=gmail.com@python.org> On Behalf Of Rob Cliffe via Python-list
> Sent: Thursday, December 15, 2022 8:31 AM
> To: python-list@python.org
> Subject: Re: Single line if statement with a continue
>
>
>
> On 15/12/2022 04:35, Chris Angelico wrote:
>> On Thu, 15 Dec 2022 at 14:41, Aaron P <transreductionist@gmail.com> wrote:
>>> I occasionally run across something like:
>>>
>>> for idx, thing in enumerate(things):
>>> if idx == 103:
>>> continue
>>> do_something_with(thing)
>>>
>>> It seems more succinct and cleaner to use:
>>>
>>> if idx == 103: continue.
>>>
>>>
>>> Nothing at all wrong with writing that on a single line. If you have
>>> issues with Flake8 not accepting your choices, reconfigure Flake8 :)
>>>
>>> ChrisA
> I'm so glad that Chris and others say this. It (i.e. if plus break/continue/return on a single line) is something I have quite often done in my own code, albeit with a feeling of guilt that I was breaking a Python taboo. Now I will do it with a clear conscience. 😁
> Best wishes
> Rob Cliffe
> --
> https://mail.python.org/mailman/listinfo/python-list
>

Re: Single line if statement with a continue

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!fu-berlin.de!uni-berlin.de!not-for-mail
From: rosuav@gmail.com (Chris Angelico)
Newsgroups: comp.lang.python
Subject: Re: Single line if statement with a continue
Date: Sun, 18 Dec 2022 11:59:44 +1100
Lines: 9
Message-ID: <mailman.1222.1671325197.20444.python-list@python.org>
References: <af8635f1-30b9-4a0b-b9f8-d81f2c54960an@googlegroups.com>
<CAPTjJmp7itCdQQ76UQttWg_A8f5Y=NHnSBe_t_BFWXiQEP0nUw@mail.gmail.com>
<4f21e136-dbec-3aed-60e2-c3908bebce71@btinternet.com>
<006801d91273$5cfffe80$16fffb80$@gmail.com>
<CAPTjJmpZherAhc84GwxSvUFZYvbJS7efTvauQDfUVjO941KxjQ@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de v/pm+u2PHAE6ztXwKrDxywyfD+hCYsWsjYCnkfxUjoXg==
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=AbwWhBMh;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.007
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; '2022': 0.05; 'sun,': 0.07;
'compiler': 0.09; 'chrisa': 0.16; 'deprecated,': 0.16;
'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16;
'interpreter': 0.16; 'received:209.85.218': 0.16;
'subject:continue': 0.16; 'wrote:': 0.16; 'to:addr:python-list':
0.20; 'code': 0.23; 'binary': 0.26; 'wrong': 0.28; 'dec': 0.31;
'(as': 0.32; 'programmers': 0.32; 'message-id:@mail.gmail.com':
0.32; 'header:In-Reply-To:1': 0.34; 'received:google.com': 0.34;
'from:addr:gmail.com': 0.35; 'errors': 0.36; 'source': 0.36;
'change': 0.36; 'received:209.85': 0.37; 'received:209': 0.39;
'use': 0.39; 'subject': 0.63; 'your': 0.64
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=rsGrB0EIlKygZDSN8Vs5zDHd92RQZocQd3VsKfp7AEE=;
b=AbwWhBMh+i2aBWU+bnXi8g0ic360I8Y+tMFTc7a6mk9YViy9DGaY2RTbQONfJW98Px
dPlGN7QbhFWbkmPJOPbumi6SXarmk1UQGUkcEaXeznsK8quBQt0Z5QXl5LHpGmtHqBHI
kro/XDd/UKz+KatoI2uOWSx6+nIcwEWfWSGCJcTwy3x+qOWzQoPNAW4SZzh+pTe7eh0X
7jl3Ut6n+uhCLrLZoESeKlSvlq2zm9G/sFQznvSJEYDhMyAhlkbbyqR4h2uoXOnUft5+
RcnJMUtKPiY6sQRgmRGyjjKuAffFXOFG+nO0TJeprKRuvrkvMaZ10Ny/izAPaojC/5Is
bwCA==
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=rsGrB0EIlKygZDSN8Vs5zDHd92RQZocQd3VsKfp7AEE=;
b=T4sQoYkE1ohrdo/Ie4mavENKqnWaeGB2PE+NkmXXVHDTfTPCE1WpXx4xDoc70HDubt
Ywex7fl/QlTSE683yaFMcFHklQySw3C9jKNWa46mugl1y7I2PQqp05vCqw+ou0hfxd3U
cwnEt/cU3pDnDAZal0/QE7Fer4tMxFYZy9fSowbVS7pDHagvRgvPZVmMBYXpVgZzsp7g
pRD+HvI4dlUOaaT8OyPNq+f7b9dNp6OfhC+9FNRyR0WBJ2F+oFuq4lYz2SYF7XCk5kd5
5BWqsRDka/4Jqf2532p7FyzxL6LlzlFCY+7YR9peel1aniOTyENDHh00R6bQk4GjJoQi
SmyA==
X-Gm-Message-State: ANoB5pkDgU+yEUi3iCKbQZzHYCVSe1VePfTTUQRBNRkCeYSHBTnBLc8R
D2xuWZ+Soph7TzDmSWSQFEy0fZY4odLbqwcn4XgLXDGg
X-Google-Smtp-Source: AMrXdXtdL/sQKfrzJXonwQVtL/2RiprSirsoeSiG9n2OCmw9KYFBRYr0pVL063tsOy5YiM+76F8J3DLYrVOiBChJDhk=
X-Received: by 2002:a17:907:cb84:b0:7c4:efa5:b1ea with SMTP id
un4-20020a170907cb8400b007c4efa5b1eamr1945144ejc.335.1671325196101; Sat, 17
Dec 2022 16:59:56 -0800 (PST)
In-Reply-To: <006801d91273$5cfffe80$16fffb80$@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: <CAPTjJmpZherAhc84GwxSvUFZYvbJS7efTvauQDfUVjO941KxjQ@mail.gmail.com>
X-Mailman-Original-References: <af8635f1-30b9-4a0b-b9f8-d81f2c54960an@googlegroups.com>
<CAPTjJmp7itCdQQ76UQttWg_A8f5Y=NHnSBe_t_BFWXiQEP0nUw@mail.gmail.com>
<4f21e136-dbec-3aed-60e2-c3908bebce71@btinternet.com>
<006801d91273$5cfffe80$16fffb80$@gmail.com>
 by: Chris Angelico - Sun, 18 Dec 2022 00:59 UTC

On Sun, 18 Dec 2022 at 10:59, <avi.e.gross@gmail.com> wrote:
>
> If a compiler or interpreter HAPPILY (as happy as machines/code get) compiles or interprets your code without errors every time you use it a certain way, then it is not wrong to use it. Of course if it subject to change or already deprecated, ...
>

Source code is, first and foremost, for programmers to read. You're
confusing it with binary executables.

ChrisA

Re: Single line if statement with a continue

<cbeuph57qc2u30a5l4pk2ij8t9l3cno9le@4ax.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border-2.nntp.ord.giganews.com!nntp.giganews.com!Xl.tags.giganews.com!local-1.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Sun, 18 Dec 2022 16:07:17 +0000
From: wlfraed@ix.netcom.com (Dennis Lee Bieber)
Newsgroups: comp.lang.python
Subject: Re: Single line if statement with a continue
Date: Sun, 18 Dec 2022 11:07:18 -0500
Organization: IISS Elusive Unicorn
Message-ID: <cbeuph57qc2u30a5l4pk2ij8t9l3cno9le@4ax.com>
References: <af8635f1-30b9-4a0b-b9f8-d81f2c54960an@googlegroups.com>
User-Agent: ForteAgent/8.00.32.1272
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Lines: 31
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-nxUQk1kUhJp5ka/VpWGtPZoJ3X6aqGZTqQ8G5Dbz6pxhw1jMhk+ZXLt4VDTi8+UXjJRyofbRhSE5jTO!OwwxiCxnpFKlXvOESfC9M7lcgd56rwwVeZ47cRymfa7MXcXzO36zTjvTVxQtysykF7YLLB59
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
 by: Dennis Lee Bieber - Sun, 18 Dec 2022 16:07 UTC

On Wed, 14 Dec 2022 10:53:10 -0800 (PST), Aaron P
<transreductionist@gmail.com> declaimed the following:

Late response here, and the concept may have been covered in
skimmed-over posts..

>I occasionally run across something like:
>
>for idx, thing in enumerate(things):
> if idx == 103:
> continue
> do_something_with(thing)
>

For this example, I'd probably reverse the condition.

if idx != 103:
do_something_with(thing)

and hence completely drop the "continue" -- after all, if idx is 103, the
if statement falls through, and the end of the loop acts as an implicit
"continue"

OTOH: if the "if/continue" is buried in four or five layers of
conditionals, it could be cleaner than trying to configure the conditionals
to have a chained exit.

--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com http://wlfraed.microdiversity.freeddns.org/

Re: Single line if statement with a continue

<loop-20221218174906@ram.dialup.fu-berlin.de>

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.python
Subject: Re: Single line if statement with a continue
Date: 18 Dec 2022 16:49:27 GMT
Organization: Stefan Ram
Lines: 36
Expires: 1 Dec 2023 11:59:58 GMT
Message-ID: <loop-20221218174906@ram.dialup.fu-berlin.de>
References: <af8635f1-30b9-4a0b-b9f8-d81f2c54960an@googlegroups.com> <cbeuph57qc2u30a5l4pk2ij8t9l3cno9le@4ax.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de NBjRB1KFzutWhiTd4D9i8wSO+3L8fV9rVu0DtbyqmxOeK6
X-Copyright: (C) Copyright 2022 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE, en-US, it, fr-FR
 by: Stefan Ram - Sun, 18 Dec 2022 16:49 UTC

Dennis Lee Bieber <wlfraed@ix.netcom.com> writes:
>>for idx, thing in enumerate(things):
>> if idx == 103:
>> continue
>> do_something_with(thing)
>>
> For this example, I'd probably reverse the condition.
> if idx != 103:
> do_something_with(thing)

The first four lines of the quotation above cannot be a
complete program as "do_something_with" is not defined
therein, so they must be part of a larger program.
If, in this larger program, something still follows
"do_something_with(thing)" in the loop, the new program
after the transformation might not show the same behavior.

def do_something_with( what ):
print( what )

for i in range( 3 ):
thing = "it"
if i == 2:
continue
do_something_with( thing )
print( "B" )

print()

for i in range( 3 ):
thing = "it"
if i != 2:
do_something_with( thing )
print( "B" )

Re: Single line if statement with a continue

<d14e4dc6-d785-4d3b-adb5-1be673bc93d7n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.python
X-Received: by 2002:ac8:7382:0:b0:3a8:2e9f:6ae9 with SMTP id t2-20020ac87382000000b003a82e9f6ae9mr389860qtp.293.1671398872697;
Sun, 18 Dec 2022 13:27:52 -0800 (PST)
X-Received: by 2002:a05:6870:4d19:b0:144:9310:987b with SMTP id
pn25-20020a0568704d1900b001449310987bmr971381oab.268.1671398872389; Sun, 18
Dec 2022 13:27:52 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.python
Date: Sun, 18 Dec 2022 13:27:52 -0800 (PST)
In-Reply-To: <mailman.1220.1671321471.20444.python-list@python.org>
Injection-Info: google-groups.googlegroups.com; posting-host=62.249.217.89; posting-account=FHqkeAoAAACbOpBCHa7K6JTmToKlWNDp
NNTP-Posting-Host: 62.249.217.89
References: <AQJI2jgjpoZjOo45TmZxO3GBPwt80gLd5Qc0AIkvxEStd+t1gA==>
<af8635f1-30b9-4a0b-b9f8-d81f2c54960an@googlegroups.com> <CAPTjJmp7itCdQQ76UQttWg_A8f5Y=NHnSBe_t_BFWXiQEP0nUw@mail.gmail.com>
<006801d91273$5cfffe80$16fffb80$@gmail.com> <4f21e136-dbec-3aed-60e2-c3908bebce71@btinternet.com>
<mailman.1220.1671321471.20444.python-list@python.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <d14e4dc6-d785-4d3b-adb5-1be673bc93d7n@googlegroups.com>
Subject: Re: Single line if statement with a continue
From: guinness.tony@gmail.com (Tony Oliver)
Injection-Date: Sun, 18 Dec 2022 21:27:52 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1635
 by: Tony Oliver - Sun, 18 Dec 2022 21:27 UTC

On Saturday, 17 December 2022 at 23:58:11 UTC, avi.e...@gmail.com wrote:
> Is something sort of taboo when using something like a computer language to write a program?

With what else would you write a program?


devel / comp.lang.python / Single line if statement with a continue

Pages:12
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor