[Python-ideas] Explicit variable capture list

Stephen J. Turnbull stephen at xemacs.org
Sun Jan 24 01:27:52 EST 2016


Guido,

Thank you for taking the trouble to address my rather confused post.

Guido van Rossum writes:

 > If I were to deconstruct the original statement, I would start by
 > replacing the list comprehension with a plain old for loop.

I did that.  But that actually doesn't bother me because the loop
index's identifier doesn't go out of scope.  I now see why that's a
red herring, but maybe documentation can be improved.

Anyway, I wrote that post before seeing your explanation that things
just aren't that difficult, they all follow from "variable reference
as dictionary lookup".  The clue I needed was the way to view a scope
as an object, and then realize that all free variable references are
the same, except for visibility of the relevant scope to the other
code at the call site.

For me it's now a documentation issue (I know why the comprehension of
lambdas work as they do, and I also know how to get the "expected",
more useful result).  I'll go take a look at the language reference,
and tutorial, and see if I think they can be improved.



More information about the Python-ideas mailing list