[Python-ideas] Re: Make for/while loops nameable.

2020-12-08 Thread Ricky Teachey
On Tue, Dec 8, 2020 at 10:42 AM David Mertz wrote: > On Tue, Dec 8, 2020 at 3:31 PM Ricky Teachey wrote: > >> I agree with the person who called this a brilliant solution. Here is the >> code from the link for completeness: >> > > I'm not diss'ing the approach. But it doesn't really save that m

[Python-ideas] Re: Make for/while loops nameable.

2020-12-08 Thread David Mertz
On Tue, Dec 8, 2020 at 3:31 PM Ricky Teachey wrote: > I agree with the person who called this a brilliant solution. Here is the > code from the link for completeness: > I'm not diss'ing the approach. But it doesn't really save that much over a sentinel variable `break_to_middle`. And if you wa

[Python-ideas] Re: Make for/while loops nameable.

2020-12-08 Thread Ricky Teachey
On Mon, Dec 7, 2020 at 6:27 PM Daniel Moisset wrote: > For the likely rare situation where I'd want to do this rather than > refactoring into a function, I might try with something like this without > requiring changes to the language: > > from contextlib import contextmanager > > @contextmanager

[Python-ideas] Re: Make for/while loops nameable.

2020-12-08 Thread Stephen J. Turnbull
Daniel Moisset writes: > For the likely rare situation where I'd want to do this rather than > refactoring into a function, I might try with something like this without > requiring changes to the language: > @contextmanager > def breakable(): Of course this doesn't address Serhiy's case whe

[Python-ideas] Re: Make for/while loops nameable.

2020-12-07 Thread Henk-Jaap Wagenaar
Just want to say that that is brilliant, and I would have not thought of that, that's a cool idea! Only annoyance is that it introduces an indentation, otherwise it'd be perfect! On Mon, 7 Dec 2020 at 23:30, Daniel Moisset wrote: > For the likely rare situation where I'd want to do this rather t

[Python-ideas] Re: Make for/while loops nameable.

2020-12-07 Thread Daniel Moisset
For the likely rare situation where I'd want to do this rather than refactoring into a function, I might try with something like this without requiring changes to the language: from contextlib import contextmanager @contextmanager def breakable(): class Break(Exception): pass def breaker(

[Python-ideas] Re: Make for/while loops nameable.

2020-12-06 Thread Stephen J. Turnbull
David Mertz writes: > It's cute. Cute is for bunnies and Ghibli anime. :-) > And really quite readable. But it's not writeable. Heh. They look like misplaced apostrophes on my screen in my English buffers. I'd have to go to a 1.3x (maybe 1.5x) font to be sure what I'm looking at. And I'm

[Python-ideas] Re: Make for/while loops nameable.

2020-12-05 Thread David Mertz
On Sat, Dec 5, 2020 at 6:20 PM Steve Barnes wrote: > How about reserving unicode numeric superscript characters 0..9 as label > identifiers only to be used for loop & break, etc. Then the example below > would become: > > > while¹ not processed(): > > for² x in the_stuff: > > if all_d

[Python-ideas] Re: Make for/while loops nameable.

2020-12-05 Thread Alexis Masson
How about reserving unicode numeric superscript characters 0..9 as label identifiers only to be used for loop & break, etc. Then the example below would become: while¹ not processed():     for x in the_stuff as 37:     if all_done(x): break¹ I don't really care how the labels are spelle

[Python-ideas] Re: Make for/while loops nameable.

2020-12-05 Thread Steve Barnes
ertz Sent: 05 December 2020 17:32 To: Alexis Masson Cc: python-ideas Subject: [Python-ideas] Re: Make for/while loops nameable. On Sat, Dec 5, 2020 at 11:05 AM Alexis Masson mailto:a.masson...@ntymail.com>> wrote: I agree with you that the point of `break x` — labeled or numbered — is to

[Python-ideas] Re: Make for/while loops nameable.

2020-12-05 Thread David Mertz
On Sat, Dec 5, 2020 at 11:05 AM Alexis Masson wrote: > I agree with you that the point of `break x` — labeled or numbered — is to > target a specific loop to "jump" to, but I'm not comfortable with > introducing labels to Python. The reason for this is that they look too > much like identifiers,

[Python-ideas] Re: Make for/while loops nameable.

2020-12-05 Thread Alexis Masson
Le 04/12/2020 à 21:18, David Mertz a écrit : I like the idea of named breaks, but I *hate* the idea of numerically labeled breaks, whether numbered from the inside or from the outside. On the occasions—which are actually relatively frequent—that I want to break all the way out of an inner loop

[Python-ideas] Re: Make for/while loops nameable.

2020-12-04 Thread Rob Cliffe via Python-ideas
On 04/12/2020 20:18, David Mertz wrote: I like the idea of named breaks, but I *hate* the idea of numerically labeled breaks, whether numbered from the inside or from the outside. [snip] The problem with numbers, beyond just being harder to count out, is that they are fragile under refactorin

[Python-ideas] Re: Make for/while loops nameable.

2020-12-04 Thread David Mertz
I like the idea of named breaks, but I *hate* the idea of numerically labeled breaks, whether numbered from the inside or from the outside. On the occasions—which are actually relatively frequent—that I want to break all the way out of an inner loop, I wind up using a sentinel STOP variable. I kn

[Python-ideas] Re: Make for/while loops nameable.

2020-12-04 Thread Aveheuzed
I think this is the kind of feature that can very easily be abused. Whenever I want to break out of a nested loop I take this as an opportunity to extract the loop into its own function and use the return statement to break out of the loop. IMO this is a lot better than having named or indexe

[Python-ideas] Re: Make for/while loops nameable.

2020-12-04 Thread Valentin Berlier
I think this is the kind of feature that can very easily be abused. Whenever I want to break out of a nested loop I take this as an opportunity to extract the loop into its own function and use the return statement to break out of the loop. IMO this is a lot better than having named or indexed l

[Python-ideas] Re: Make for/while loops nameable.

2020-12-04 Thread Abdulla Al Kathiri
Oh I like it. Indexing the loop number from innermost to outermost makes more sense. The starting implicit index in case of alone continue/break will always be known (either 1 or zero). Of course it doesn’t make sense to use negative index for the loop because breaking from the parent loop will

[Python-ideas] Re: Make for/while loops nameable.

2020-12-03 Thread Aveheuzed
Why not start at break 0 not break 1, similar to sequences starting at index 0? Maybe if break alone without integer, it breaks from the loop it is at similar to the behavior we have right now in Python. E.g., for matrix in matrix_array : # Index 0     for x in range(0,10) : # Index 1   

[Python-ideas] Re: Make for/while loops nameable.

2020-12-03 Thread Abdulla Al Kathiri
Why not start at break 0 not break 1, similar to sequences starting at index 0? Maybe if break alone without integer, it breaks from the loop it is at similar to the behavior we have right now in Python. E.g., for matrix in matrix_array : # Index 0 for x in range(0,10) : # Index 1

[Python-ideas] Re: Make for/while loops nameable.

2020-12-03 Thread Aveheuzed
Hi everyone, I'm not in favor of naming loops, as this looks too much like variable. (What happens when variable names and loop names names collide ? Does the loop identifier bind to anything ?) On the other hand, I like the feature very much, and I have thought about it in the past. My take

[Python-ideas] Re: Make for/while loops nameable.

2020-12-03 Thread Chris Angelico
On Fri, Dec 4, 2020 at 2:42 AM Jonathan Fine wrote: > > Hi > > On Thu, Dec 3, 2020 at 2:02 PM Chris Angelico wrote: >> >> well... uhhh Technically you can do that already >> >> for a in aaa: >> for b in bbb: >> if condition(a, b): >> break >> else: >> c

[Python-ideas] Re: Make for/while loops nameable.

2020-12-03 Thread Serhiy Storchaka
03.12.20 15:59, Chris Angelico пише: > well... uhhh Technically you can do that already > > for a in aaa: > for b in bbb: > if condition(a, b): > break > else: > continue # We didn't break from b, so continue a > break # We did break b, so break a >

[Python-ideas] Re: Make for/while loops nameable.

2020-12-03 Thread Jonathan Fine
Hi On Thu, Dec 3, 2020 at 2:02 PM Chris Angelico wrote: > well... uhhh Technically you can do that already > > for a in aaa: > for b in bbb: > if condition(a, b): > break > else: > continue # We didn't break from b, so continue a > break # We did b

[Python-ideas] Re: Make for/while loops nameable.

2020-12-03 Thread Chris Angelico
On Fri, Dec 4, 2020 at 12:25 AM Jonathan Fine wrote: > > Hi Jonatan > > Please consider > for a in aaa: > for b in bbb: > if condition(a, b): > break > KEYWORD: > break > where KEYWORD is like else, but with the opposite semantics. I thin

[Python-ideas] Re: Make for/while loops nameable.

2020-12-03 Thread Jonathan Fine
Hi Jonatan Please consider for a in aaa: for b in bbb: if condition(a, b): break KEYWORD: break where KEYWORD is like else, but with the opposite semantics. I think this does exactly what you asked for, in your example. In July this year

[Python-ideas] Re: Make for/while loops nameable.

2020-12-03 Thread Paul Sokolovsky
Hello, On Thu, 03 Dec 2020 11:06:41 - "Jonatan " wrote: > Hi, sometimes I do nested loops and I want to break specific loop, > outer/inner etc. I need to do an ugly thing with for..else and it's > annoying. > > It'd be nice if we could do so: > for i in range(10) as loop_i: > for j in r

[Python-ideas] Re: Make for/while loops nameable.

2020-12-03 Thread M.-A. Lemburg
On 03.12.2020 12:06, Jonatan wrote: > Hi, sometimes I do nested loops and I want to break specific loop, > outer/inner etc. > I need to do an ugly thing with for..else and it's annoying. > > It'd be nice if we could do so: > for i in range(10) as loop_i: > for j in range(i, i + 10) as loop_j

[Python-ideas] Re: Make for/while loops nameable.

2020-12-03 Thread Mathew Elman
I personally am +1 for something like this. What about for use with `continue` as well? e.g. > for i in range(10) as i_loop: > for j in range(i, i + 10) as j_loop: > if i + j == 9: > continue i_loop which will break out of j_loop and go to the next i (as if the `continue

[Python-ideas] Re: Make for/while loops nameable.

2020-12-03 Thread Paul Moore
On Thu, 3 Dec 2020 at 11:07, Jonatan wrote: > > Hi, sometimes I do nested loops and I want to break specific loop, > outer/inner etc. > I need to do an ugly thing with for..else and it's annoying. > > It'd be nice if we could do so: > for i in range(10) as loop_i: > for j in range(i, i + 10)

[Python-ideas] Re: Make for/while loops nameable.

2020-12-03 Thread Abdur-Rahmaan Janhangeer
Greetings list, I wonder if the issue should be named as: introduce absolute break in Python as if you have 5 nested loops (which you probably should not), breaking loop_i won't do anything Kind Regards, Abdur-Rahmaan Janhangeer about | blog