setting variables in the local namespace

Carl Banks pavlovevidence at gmail.com
Tue Oct 13 13:57:00 EDT 2009


On Oct 13, 9:39 am, Mick Krippendorf <mad.m... at gmx.de> wrote:
> Yes, and, uh, yes. "locals()['foo'] = bar" works in that it does the
> same thing as "foo = bar". So why don't you write that instead?

Lemme guess.

You tried this at the interactive prompt and concluded it worked in
general, right?

Even though when we speak of local variables, we usually are referring
to local variables inside a function, you didn't actually test whether
locals() works in a function, did you?

Because if you had you would have seen it doesn't work.


One of these days we're going to have a thread like this where no one
makes this mistake.  Don't know when, but one day it will happen.


Carl Banks



More information about the Python-list mailing list