[Python-ideas] Explicit variable capture list

Greg Ewing greg.ewing at canterbury.ac.nz
Sat Jan 23 16:16:11 EST 2016


Guido van Rossum wrote:
> So, I don't really want to introduce "for new x in ..." because it 
> suddenly introduces a completely different concept into the language,
>
> What 
> dict hold x in "for new x ..."? It would have to be considered a new 
> dict created just to hold x, but other variables assigned in the body of 
> the for loop would still be in the dict holding all the other locals of 
> the function.

We could say that the body of a "for new" loop is a nested
scope in which all other referenced variables are implicitly
declared "nonlocal".

-- 
Greg


More information about the Python-ideas mailing list