[Tutor] Addressing a variable whose name is the value of a string
kent37 at tds.net
Mon Apr 9 01:58:33 CEST 2007
John Clark wrote:
> But I am not sure what the pros/cons for doing something like this would
locals() should be considered read-only. From the docs:
Update and 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
At global scope, locals() == globals() and modifying locals() will work.
Within a function, modifying locals() will not do what you want.
More information about the Tutor