Re: Single line if statement with a continue

2022-12-19 Thread Peter J. Holzer
On 2022-12-18 16:49:27 +, Stefan Ram wrote: > Dennis Lee Bieber 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: > >

Re: Single line if statement with a continue

2022-12-18 Thread Tony Oliver
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? -- https://mail.python.org/mailman/listinfo/python-list

Re: Single line if statement with a continue

2022-12-18 Thread Dennis Lee Bieber
On Wed, 14 Dec 2022 10:53:10 -0800 (PST), Aaron P 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_s

Re: Single line if statement with a continue

2022-12-17 Thread Chris Angelico
On Sun, 18 Dec 2022 at 10:59, 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, ... >

Re: Single line if statement with a continue

2022-12-17 Thread Thomas Passin
er 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 On Behalf Of

RE: Single line if statement with a continue

2022-12-17 Thread avi.e.gross
lem 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 On Behalf Of Rob Cliffe via Python-list Sent: Thursday, December 15, 2022 8:31 AM To: python-list@python.or

Re: Single line if statement with a continue

2022-12-17 Thread dn
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 wrote: I occasionally run across something like: for idx, thing in enumerate(things): if idx == 103: continue do_something_with(thing) It

Re: Single line if statement with a continue

2022-12-17 Thread Abdullah Nafees
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

Re: Single line if statement with a continue

2022-12-17 Thread Rob Cliffe via Python-list
On 15/12/2022 04:35, Chris Angelico wrote: On Thu, 15 Dec 2022 at 14:41, 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 == 10

Re: Single line if statement with a continue

2022-12-15 Thread Grant Edwards
On 2022-12-15, MRAB 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 li

Re: Single line if statement with a continue

2022-12-15 Thread Thomas Passin
On 12/15/2022 3:58 AM, Chris Green wrote: Thomas Passin 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 mul

Re: Single line if statement with a continue

2022-12-15 Thread MRAB
: Python-list 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 writes: I always try to avoid multiple returns from functions/methods, as soon as things get complex it's all to easy to

Re: Single line if statement with a continue

2022-12-15 Thread Weatherby,Gerard
easily handled by the try / finally construct. From: Python-list on behalf of avi.e.gr...@gmail.com Date: Thursday, December 15, 2022 at 2:07 PM To: python-list@python.org Subject: RE: Single line if statement with a continue *** Attention: This is an external email. Use caution responding

RE: Single line if statement with a continue

2022-12-15 Thread avi.e.gross
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 On Behalf Of Stefan Ram Sent: Thursday, December 15, 2022 7:42 AM To: python-list@python.org Subject: Re: Single line if

Re: Single line if statement with a continue

2022-12-15 Thread Cecil Westerhof via Python-list
r...@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

Re: Single line if statement with a continue

2022-12-15 Thread Chris Green
Thomas Passin 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 prog

RE: Single line if statement with a continue

2022-12-14 Thread avi.e.gross
27;s code. -Original Message- From: Python-list 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

Re: Single line if statement with a continue

2022-12-14 Thread Chris Angelico
On Thu, 15 Dec 2022 at 16:29, Thomas Passin 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 oka

Re: Single line if statement with a continue

2022-12-14 Thread Thomas Passin
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,

Re: Single line if statement with a continue

2022-12-14 Thread dn
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

Re: Single line if statement with a continue

2022-12-14 Thread Chris Angelico
On Thu, 15 Dec 2022 at 14:41, 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