Why are both locals() and globals() set?
MRAB
python at mrabarnett.plus.com
Sat Dec 23 13:55:33 EST 2017
On 2017-12-23 04:01, Peng Yu wrote:
> Hi, The following example shows that both locals() and globals() are
> updated when x and f are defined. Shouldn't they be considered and
> global variable and functions only? Why does it make sense to set
> locals() as well? Thanks.
>
It's "local" in the sense that it's in the current scope, so in a
function it's local to that function, and in the main code of a module
it's local to that module as well as being "global".
[snip]
More information about the Python-list
mailing list