How do I do this? (eval() on the left hand side)

caleb.hattingh at caleb.hattingh at
Thu Dec 9 13:26:29 CET 2004

Both Peters :)

Sure, I must concede that the problem here was my expectation of how
things should work.

Thanks for the explanations.  I still don't really know whether this
behaviour of locals() is the result of a design decision, or an
implementation artifact of CPython, but at least I have a clear idea of
how to play nice with locals().


Peter Otten wrote:
> Caleb Hattingh wrote:
> > I am convinced now that locals() doesn't work as (I) expected.
> > says there was some or other reason why locals() as used in this
> > 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
> > is a character flaw, but I really do like to know what works, when
> > works, and when it doesn't work.
> I think Peter Hansen has answered that. Your expectations were just
> > In this scenario, we can see it doesn't work.  To my eyes, it
doesn't work
> > *in the way I expect* (which is highly subjective, no argument
> > Would this be a situation where it would be nice to have an
> > thrown if locals() is assigned to in a scope where it is not
> If python were to throw an exception, it should always be thrown. But
> the wrong one to worry about that as I didn't even find a single
> globals()[name] = value
> assignment in my scripts. I want to know a variable's name, or I put
it in a
> dictionary.
> > It would also be nice if globals and locals behaved the same,
> > only in scope (which is what I expected originally anyway).  But we
> > have everything, I guess :)
> That would mean that both would become read-only, I guess, but I
don't see
> that happen.
> Peter

More information about the Python-list mailing list