Re: The “does Python have variables?” debate

Chris Angelico rosuav at gmail.com
Wed May 7 10:30:29 EDT 2014


On Thu, May 8, 2014 at 12:17 AM, Marko Rauhamaa <marko at pacujo.net> wrote:
> Weird. Some other tests of mine did work. But:
>
>    Note: The contents of this dictionary should not be modified; changes
>    may not affect the values of local and free variables used by the
>    interpreter. [<URL:
>    https://docs.python.org/2/library/functions.html#locals>]

If you test locals() at module level (including the interactive
interpreter), things will work, because it just returns the same dict
as globals() returns. It's only inside an actual function that it's
different and magical.

ChrisA



More information about the Python-list mailing list