Message282200
The locals() documentation [1] says that "Free variables are returned by locals() when it is called in function blocks". A free variable inside a function has a global scope, and in fact it is not returned by locals()::
>>> x = 33
>>> def foo():
... print(x)
... print(locals())
...
>>> foo()
33
{}
Maybe "function blocks" here means "closure"? Does the doc mean this?
>>> def foo():
... x = 33
... def moo():
... print(x)
... print(locals())
... return moo
...
>>> moo = foo()
>>> moo()
33
{'x': 33}
In that case, I think it is better to write "closures" instead of
"function blocks".
[1] https://docs.python.org/3/library/functions.html#locals |
|
Date |
User |
Action |
Args |
2016-12-01 16:54:37 | marco.buttu | set | recipients:
+ marco.buttu, docs@python |
2016-12-01 16:54:37 | marco.buttu | set | messageid: <1480611277.06.0.950152525221.issue28853@psf.upfronthosting.co.za> |
2016-12-01 16:54:37 | marco.buttu | link | issue28853 messages |
2016-12-01 16:54:36 | marco.buttu | create | |
|