How about doing it pythonic way then, "everything is a hack on a symbol
table".
Let normal loops remain normal loops.
Let's introduce a special construction:
> for x in iterator as loop_control_object:
> loop_body(loop_control_object)
The iterator in the loop would be wrapped inside
I think a Python version of longjmp() and setjmp() might be easier to
understand.
On Sun, May 12, 2019 at 6:23 PM David Mertz wrote:
> On Sun, May 12, 2019, 5:36 PM Paul Moore wrote:
>
>> On Sun, 12 May 2019 at 21:06, David Mertz wrote:
>> > I thought of 'as' initially, and it reads well as
On Sun, May 12, 2019, 5:36 PM Paul Moore wrote:
> On Sun, 12 May 2019 at 21:06, David Mertz wrote:
> > I thought of 'as' initially, and it reads well as English. But it felt
> to me like the meaning was too different from the other meanings of 'as' in
> Python. I might be persuaded otherwise.
>
On Sun, May 12, 2019, 3:33 PM Gustavo Carneiro wrote:
> # Hypothetical future labelled break:
>> def find_needle_in_haystacks():
>> for haystack in glob.glob('path/to/stuff/*') label HAYSTACKS:
>> fh = open(fname)
>> header = fh.readline()
>> if get_format(header) ==
I thought of "we could return immediately" shortly after I posted it. Yes,
that's true in the example I wrote. But it's easy enough to vary it so that
something happens after the loop as well. I also noticed that for the
simple version, it might be slightly shorter to put the conditional inside
On Sun, 12 May 2019 at 18:26, David Mertz wrote:
> To be clear in this thread, I don't think I'm really ADVOCATING for a
> multi-level break. My comments are simply noting that I personally fairly
> often encounter the situation where they would be useful. At the same
> time, I worry about
To be clear in this thread, I don't think I'm really ADVOCATING for a
multi-level break. My comments are simply noting that I personally fairly
often encounter the situation where they would be useful. At the same
time, I worry about Python gaining sometimes-useful features that
complicate the
On 2019-05-12 10:44, Steven D'Aprano wrote:
On Sun, May 12, 2019 at 11:16:21AM +0200, Oleg Broytman wrote:
On Sun, May 12, 2019 at 01:36:28AM -0700, Elias Tarhini
wrote:
> If I may propose `break n` as a replacement for the original message's
> `break break ... break`, where n>0 is the number
The concrete example I was working on when I started to miss double
break. This is an implementation of polynomial long division in Galois
field. Almost unmodified.
With outer break, I would't need to use the `running` variable. In fact,
for mathematical clarity, I would like to put a
On Sun, May 12, 2019 at 11:16:21AM +0200, Oleg Broytman wrote:
> On Sun, May 12, 2019 at 01:36:28AM -0700, Elias Tarhini
> wrote:
> > If I may propose `break n` as a replacement for the original message's
> > `break break ... break`, where n>0 is the number of contiguous loops to
> > break out
On Sun, May 12, 2019 at 01:36:28AM -0700, Elias Tarhini
wrote:
> If I may propose `break n` as a replacement for the original message's
> `break break ... break`, where n>0 is the number of contiguous loops to
> break out of and `break 1` is synonymous with `break`. Seems easier on my
>
On Sun, May 12, 2019 at 1:30 PM David Mertz wrote:
>
> I'll try to find a concrete one tomorrow. I did this recently, but I might
> have factored it away somehow. The real life code has lots of extraneous
> parts that need to be removed or simplified though. Both because they aren't
> FLOSS,
I'll try to find a concrete one tomorrow. I did this recently, but I might
have factored it away somehow. The real life code has lots of extraneous
parts that need to be removed or simplified though. Both because they
aren't FLOSS, and because the details would muddy things. "Trimmed from
real"
On Sun, May 12, 2019 at 1:16 PM David Mertz wrote:
>
> Ok, sure. But what if different seen_enough() conditions are in the two inner
> loops? By "break to outer" ... I mean, don't get any more 'main' from
> 'stuff'. I meant to dig through some real code, but forgot because I was
> writing code
On Sun, May 12, 2019 at 12:43 PM David Mertz wrote:
>
> Terry reminds me of a common case I encounter that cannot be transformed into
> a loop over itertools.product(). E.g.
>
> for main in stuff:
> if thing_about(main):
> for detail in more_stuff(stuff, main):
> if
Terry reminds me of a common case I encounter that cannot be transformed
into a loop over itertools.product(). E.g.
for main in stuff:
if thing_about(main):
for detail in more_stuff(stuff, main):
if seen_enough(detail):
# break to outer somehow
else:
On 5/11/2019 1:20 PM, haael wrote:
Python allows for breaking out from a loop through 'break' and
'continue' keywords. It would be nice if it was possible to break many
loop levels using one command.
I propose two constructions for that:
break
break break
break break break
...
continue
On Sat, May 11, 2019 at 1:22 PM haael wrote:
> Python allows for breaking out from a loop through 'break' and
> 'continue' keywords. It would be nice if it was possible to break many
> loop levels using one command.
I'm surprised no one has yet mentioned splitting off the loops into a
function
On Sun, May 12, 2019 at 3:45 AM Christopher Barker
wrote:
>
> judicious use of the for loop "else" may help here, too -- I know I often
forget it's there.
yeah, I often do this when I want to break twice but this method only
supports breaking twice at once but this doesn't support break once
and
judicious use of the for loop "else" may help here, too -- I know I often
forget it's there.
-CHB
On Sat, May 11, 2019 at 2:26 PM Adrien Ricocotam
wrote:
>
>
> > On 11 May 2019, at 23:20, David Mertz wrote:
> >
> > I don't love the 'break break' syntax idea. But I find myself wanting to
>
> On 11 May 2019, at 23:20, David Mertz wrote:
>
> I don't love the 'break break' syntax idea. But I find myself wanting to
> break out of nested loops quite often. Very rarely could this be transformed
> to an 'itertools.permutation' de-nesting, albeit perhaps more often than I
> actually
I don't love the 'break break' syntax idea. But I find myself wanting to
break out of nested loops quite often. Very rarely could this be
transformed to an 'itertools.permutation' de-nesting, albeit perhaps more
often than I actually do that.
My usual kludge is a sentinel 'break_outer' variable
On Sat, 11 May 2019 at 18:22, haael wrote:
> Breaking out from many loops at once is a common practice
Do you have evidence for this? In my experience, it's very rare
(although I concede it would be *occasionally* convenient).
In most cases where I'd consider breaking out of multiple levels of
Dear Haael
With python you can write
for i, j in something ():
# loop body
This would cover both your examples.
For the first, use itertools.product. For the second, write a custom
iterator.
--
Jonathan
On Sat, 11 May 2019, 18:22 haael, wrote:
>
> Python allows for breaking out
Python allows for breaking out from a loop through 'break' and
'continue' keywords. It would be nice if it was possible to break many
loop levels using one command.
I propose two constructions for that:
break
break break
break break break
...
continue
break continue
break break continue
25 matches
Mail list logo