[Python-ideas] Explicit variable capture list

Greg Ewing greg.ewing at canterbury.ac.nz
Sun Jan 24 15:42:52 EST 2016


Nick Coghlan wrote:
> Capturing additional values on each iteration would be possible with a
> generator expression:
> 
>     for new i, a, b, c in (i, a, b, c for i range(10)):
>         def f(x):
>             return x**i, a, b, c

I'm not sure I see the point of this. If you're needing
to capture a, b and c from an outer scope, presumably
it's because there's some outer loop that's changing
them -- in which case you can just make *that* loop
a "new" loop as well.

BTW, should there be a "while new" loop too?

-- 
Greg


More information about the Python-ideas mailing list