Message262713
The docs for locals() say that inside a function that local variables and free variables are included: https://docs.python.org/3/library/functions.html#locals
Elsewhere we use the terms "cell variables" or "nonlocals". Mathematically, the word "free" means unbound, so that isn't applicable here and isn't the usual way of describing variables in the enclosing scope.
>>> def f(x):
def g(y):
z = x + y
print(locals())
return g
>>> f(10)(20)
{'x': 10, 'y': 20, 'z': 30}
Also, I'm not sure why "x" and "y" are included in the definition for locals(). That seems strange given that "x" and "y" are not local to "g" and that "x += 1" would fail with an UnboundLocalError. |
|
Date |
User |
Action |
Args |
2016-04-01 01:31:32 | rhettinger | set | recipients:
+ rhettinger, docs@python |
2016-04-01 01:31:32 | rhettinger | set | messageid: <1459474292.87.0.515226107717.issue26683@psf.upfronthosting.co.za> |
2016-04-01 01:31:32 | rhettinger | link | issue26683 messages |
2016-04-01 01:31:31 | rhettinger | create | |
|