[Python-ideas] Re: repeat until

2022-03-02 Thread Ben Rudiak-Gould
On Tue, Mar 1, 2022 at 4:51 PM Steven D'Aprano wrote: > Then Python is the wrong language for you, because it uses exceptions to > direct control flow *wink* > > The iteration protocol uses StopIteration to end iteration. The older > sequence protocol uses IndexError for the same purpose. > I

[Python-ideas] Re: repeat until

2022-03-01 Thread Chris Angelico
On Wed, 2 Mar 2022 at 18:35, Rob Cliffe via Python-ideas wrote: > > > > On 02/03/2022 02:01, Chris Angelico wrote: > > This doesn't obscure the control flow any more than a 'while' loop, > It certainly does! I see a decorated function. Nothing tells me that > the decorator actually *calls* the

[Python-ideas] Re: repeat until

2022-03-01 Thread Rob Cliffe via Python-ideas
On 02/03/2022 02:01, Chris Angelico wrote: On Wed, 2 Mar 2022 at 12:33, Rob Cliffe via Python-ideas wrote: On 02/03/2022 01:02, Chris Angelico wrote: On Wed, 2 Mar 2022 at 10:32, Rob Cliffe via Python-ideas wrote: On 01/03/2022 22:25, Chris Angelico wrote: On Wed, 2 Mar 2022 at 09:24,

[Python-ideas] Re: repeat until

2022-03-01 Thread Chris Angelico
On Wed, 2 Mar 2022 at 17:08, Greg Ewing wrote: > > > On Wed, 2 Mar 2022 at 09:58, Rob Cliffe via Python-ideas > > wrote: > >> > >> Without testing, I am sure it would be slower. > > Does that mean if you do test it, it'll be faster? :-) > Wait, the reason my code is slow is that I don't have

[Python-ideas] Re: repeat until

2022-03-01 Thread Greg Ewing
On Wed, 2 Mar 2022 at 09:58, Rob Cliffe via Python-ideas wrote: Without testing, I am sure it would be slower. Does that mean if you do test it, it'll be faster? :-) -- Greg ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe

[Python-ideas] Re: repeat until

2022-03-01 Thread Chris Angelico
On Wed, 2 Mar 2022 at 12:33, Rob Cliffe via Python-ideas wrote: > > > > On 02/03/2022 01:02, Chris Angelico wrote: > > On Wed, 2 Mar 2022 at 10:32, Rob Cliffe via Python-ideas > > wrote: > >> > >> > >> On 01/03/2022 22:25, Chris Angelico wrote: > >>> On Wed, 2 Mar 2022 at 09:24, Steven D'Aprano

[Python-ideas] Re: repeat until

2022-03-01 Thread Rob Cliffe via Python-ideas
On 02/03/2022 01:02, Chris Angelico wrote: On Wed, 2 Mar 2022 at 10:32, Rob Cliffe via Python-ideas wrote: On 01/03/2022 22:25, Chris Angelico wrote: On Wed, 2 Mar 2022 at 09:24, Steven D'Aprano wrote: On Tue, Mar 01, 2022 at 04:04:31PM +, Rob Cliffe via Python-ideas wrote: I have

[Python-ideas] Re: repeat until

2022-03-01 Thread Chris Angelico
On Wed, 2 Mar 2022 at 10:32, Rob Cliffe via Python-ideas wrote: > > > > On 01/03/2022 22:25, Chris Angelico wrote: > > On Wed, 2 Mar 2022 at 09:24, Steven D'Aprano wrote: > >> On Tue, Mar 01, 2022 at 04:04:31PM +, Rob Cliffe via Python-ideas > >> wrote: > >> > >>> I have use cases for "do

[Python-ideas] Re: repeat until

2022-03-01 Thread Greg Ewing
On 2/03/22 12:50 pm, Rob Cliffe via Python-ideas wrote: As I see it, the original meaning of an exception (in whatever language) is "something unexpected has happened" or "something has gone wrong". Using exceptions for flow control has always been acceptable in Python. The iterator protocol

[Python-ideas] Re: repeat until

2022-03-01 Thread Steven D'Aprano
On Tue, Mar 01, 2022 at 11:50:42PM +, Rob Cliffe via Python-ideas wrote: > It doesn't feel right to me to use exceptions purely to direct control > flow.  YMMV. Then Python is the wrong language for you, because it uses exceptions to direct control flow *wink* The iteration protocol uses

[Python-ideas] Re: repeat until

2022-03-01 Thread Rob Cliffe via Python-ideas
On 01/03/2022 23:57, Ben Rudiak-Gould wrote: On Tue, Mar 1, 2022 at 2:23 PM Steven D'Aprano wrote:     try:         do_this()         if condition: raise MyBreak         do_that()         if condition: raise MyBreak         do_next_step()         if condition:

[Python-ideas] Re: repeat until

2022-03-01 Thread Ben Rudiak-Gould
On Tue, Mar 1, 2022 at 2:23 PM Steven D'Aprano wrote: > try: > do_this() > if condition: raise MyBreak > do_that() > if condition: raise MyBreak > do_next_step() > if condition: raise MyBreak > do_last_step() > except MyBreak: >

[Python-ideas] Re: repeat until

2022-03-01 Thread Rob Cliffe via Python-ideas
On 01/03/2022 22:25, Chris Angelico wrote: class MyBreak(Exception): pass try: do_this() if condition: raise MyBreak do_that() if condition: raise MyBreak do_next_step() if condition: raise MyBreak

[Python-ideas] Re: repeat until

2022-03-01 Thread Rob Cliffe via Python-ideas
On 01/03/2022 22:25, Chris Angelico wrote: On Wed, 2 Mar 2022 at 09:24, Steven D'Aprano wrote: On Tue, Mar 01, 2022 at 04:04:31PM +, Rob Cliffe via Python-ideas wrote: I have use cases for "do exactly once". Basically a sequence of actions which can be broken off (when something goes

[Python-ideas] Re: repeat until

2022-03-01 Thread Chris Angelico
On Wed, 2 Mar 2022 at 09:58, Rob Cliffe via Python-ideas wrote: > > Without testing, I am sure it would be slower. That's a trap to be careful of. Test! :) ChrisA ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to

[Python-ideas] Re: repeat until

2022-03-01 Thread Rob Cliffe via Python-ideas
Without testing, I am sure it would be slower. I suppose it would be reasonable if exceptions are raised in multiple places and the exceptions were given meaningful names. Best wishes Rob Cliffe On 01/03/2022 17:22, om wrote: How does `try/except` (with raise AppropriateException inside the

[Python-ideas] Re: repeat until

2022-03-01 Thread Chris Angelico
On Wed, 2 Mar 2022 at 09:24, Steven D'Aprano wrote: > > On Tue, Mar 01, 2022 at 04:04:31PM +, Rob Cliffe via Python-ideas wrote: > > > I have use cases for "do exactly once". > > Basically a sequence of actions which can be broken off (when something > > goes wrong and the whole process

[Python-ideas] Re: repeat until

2022-03-01 Thread Steven D'Aprano
On Tue, Mar 01, 2022 at 04:04:31PM +, Rob Cliffe via Python-ideas wrote: > I have use cases for "do exactly once". > Basically a sequence of actions which can be broken off (when something > goes wrong and the whole process should be aborted, or when something > succeeds and there is no

[Python-ideas] Re: repeat until

2022-03-01 Thread om
Along similar lines, you could also use the fact that Python does lazy-evaluation to make a do-while which forward-references variables: ``` enter_dw = True while enter_dw or (condition_with_vars_not_defined_the_first_time_through): enter_dw = False define_those_vars() ``` Sketch of a

[Python-ideas] Re: repeat until

2022-03-01 Thread Kevin Mills
If you don't like: while True: ... if whatever: break One thing I've seen people do is: condition = True while condition: ... condition = whatever You can use it if you really hate `while True` loops with `break`. ___

[Python-ideas] Re: repeat until

2022-03-01 Thread Om Joshi
How does `try/except` (with raise AppropriateException inside the block) compare to a len-1 loop?Om On Tue, 01 Mar 2022 10:04:31 -0600 python-ideas@python.org wrote I have use cases for "do exactly once". Basically a sequence of actions which can be broken off (when

[Python-ideas] Re: repeat until

2022-03-01 Thread Rob Cliffe via Python-ideas
I have use cases for "do exactly once". Basically a sequence of actions which can be broken off (when something goes wrong and the whole process should be aborted, or when something succeeds and there is no need to try alternatives) at various points with `break`.  Thus avoiding multiple

[Python-ideas] Re: repeat until

2022-03-01 Thread Eric Fahlgren
As you probably suspect, yes, it comes up every couple of years. Here's one of the recent threads (there are more, just search for 'until' in the archives), that might give you some ideas for how this discussion will progress. :)