Update locals()

jepler at unpythonic.net jepler at unpythonic.net
Sat Apr 27 16:06:08 EDT 2002


On Sat, Apr 27, 2002 at 09:57:25PM +0200, holger krekel wrote:
> Hello,
> 
> how can you dynamically update the locals() namebindings?

You don't.  See the library documentation:
    locals()
	Return a dictionary representing the current local symbol table. Warning:
	The contents of this dictionary should not be modified; changes may not
	affect the values of local variables used by the interpreter.

Whenever a name is not bound inside a function, it is a global (it could
never have a definition inside the function, so if the name comes from
anywhere, it's global).  If there's a "global" declaration, then it's
global.  If there's an assignment, then it's a local -- but changing a key
in locals still doesn't work (or is at least permitted not to work).

You probably need to rethink the way you're approaching the problem.

Jeff





More information about the Python-list mailing list