[Python-ideas] For/in/as syntax

Matthias Bussonnier bussonniermatthias at gmail.com
Fri Mar 3 13:50:19 EST 2017


Hi Brice,

On Fri, Mar 3, 2017 at 10:00 AM, Brice PARENT <contact at brice.xyz> wrote:
> Thanks Matthias for taking the time to give your opinion about it.
>
> Just to set the focus where I may have failed to point it:
> the main purpose of this proposal is the creation of the object itself, an
> object representing the loop. What we can do with it is still a sub-level of
> this proposal, as the presence of this object is what allows all these
> simplifications, and offers a lot of possibilities.
> A 2 level breaking would have to be used this way :
>
> for outerloop, i in Loop(range(4)):
>     for innerloop, j in Loop(range(3)):
>         if i==2 and j==1:
>             outerloop.brk()
>             break  # this

Thanks, I think it does make sens, I'm going to guess,
outerloop.brk(inners=True) might also be helpful if you have more
inners loops. I think that implicitely breaking inner ones might
not always be the right thing to do so having a way to not break
inner ones does make sens.

The other possibility would be to allow the Loop object to catch
raised exceptions and potentially continue running loops.
Then you could "just" use raise to break multiple loops, but
that might be a weird Loop/ContextManager hybrid.

-- 
M


More information about the Python-ideas mailing list