How do I do this? (eval() on the left hand side)
Peter Hansen
peter at engcorp.com
Wed Dec 8 18:15:22 EST 2004
Caleb Hattingh wrote:
> I am convinced now that locals() doesn't work as (I) expected. Steven
> says there was some or other reason why locals() as used in this
> context is not writable - Do you know why this is? I really do not
> like guidelines like "may not work", "is unreliable" and so on.
> Perhaps this is a character flaw, but I really do like to know what
> works, when it works, and when it doesn't work.
Those who've talked about it being "unreliable" are misstating
the Rule that you are looking for. I'll quote it below, so
that you aren't left in this unfortunate state of limbo:
The Rule of locals()
Updating locals() should not be done. Treat the
return value of locals() as read-only. Never try
to update it. End of story.
Anything that appears to suggest that locals() might sometimes
actually be writable is not really happening. Look the other
way. Pay no attention to the man behind the curtain. And
especially, whatever else you do, don't let the PSU se
More information about the Python-list
mailing list