updating locals() and globals() (WAS: How do I do this? (eval() on the left hand side))
Terry Reedy
tjreedy at udel.edu
Wed Dec 8 20:22:52 EST 2004
To respond to and summarize several posts in this discussion:
Within a function, where the local namespace is distinct from the global
(module) namespace, CPython usually implements the local namespace
internally as a fixed-length array. When this is true, locals() is a
*copy* of the local namespace and not the namespace itself. Once that dict
is created, the history of how it was created is immediately forgotten,
just as with any other ordinary Python dict.
That dict can be bound to a name or other target and modified like any
other dict, and there could be reasons to do so. However, modifying it has
no more effect on the local namespace than modifying any other local dict.
Terry J. Reedy
More information about the Python-list
mailing list