nice python solution
mwh at python.net
Wed Nov 21 11:28:22 CET 2001
Tom Loredo <loredo at astro.cornell.edu> writes:
> Steve Holden wrote:
> > > locals()[['a','b'][idx]] = val
> > >
> > This is absolutely verboten. I quote from Section 2.3 of the 2.0 manual, but
> > I don't think anything has changed since: """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.
> > """
> But the code only modifies one of the references "a" or "b", not
> the locals dictionary. Or am I missing something?
localsdict = locals()
key = ['a','b'][idx]
localsdict[key] = val
... looks like it modifies the locals dictionary to me. Don't do this.
"Well, the old ones go Mmmmmbbbbzzzzttteeeeeep as they start up and
the new ones go whupwhupwhupwhooopwhooooopwhooooooommmmmmmmmm."
-- Graham Reed explains subway engines on asr
More information about the Python-list