[Python-ideas] Explicit variable capture list

Ethan Furman ethan at stoneleaf.us
Thu Jan 28 15:09:00 EST 2016


On 01/28/2016 11:51 AM, Jim J. Jewett wrote:

> I think the only way it even *could* matter is if the loop variable is
> captured in a closure each time through the loop.  What would it
> look like for the current behavior to be intentional?
>
>      >>> for cache in (4, 5, 6, {}):
>              def f():
>                  cache['haha!'] = "I know only the last will really get used!"
>              funcs.append(f)

I think that falls into the "not legitimate" category.  ;)

--
~Ethan~



More information about the Python-ideas mailing list