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

It's me itsme at yahoo.com
Tue Dec 7 22:41:34 CET 2004


Yes, Russell, what you suggested works.

I have to chew more on the syntax to see how this is working.

because in the book that I have, it says:

    exec code [ in globaldict [, localdict] ]

...

--
It's me


"Russell Blau" <russblau at hotmail.com> wrote in message
news:31ml9mF3d9csnU1 at individual.net...
> "It's me" <itsme at yahoo.com> wrote in message
> news:Y0ptd.39767$6q2.23845 at newssvr14.news.prodigy.com...
> >
> > In REXX, for instance, one can do a:
> >
> >     interpret y' = 4'
> >
> > Since y contains a, then the above statement amongs to:
> >
> >     a = 4
> >
> > There are many situations where this is useful.   For instance, you
might
> be
> > getting an input which is a string representing the name of a variable
and
> > you wish to evaluate the expression (like a calculator application, for
> > instance).
>
> In Python, the canonical advice for this situation is, "Use a dictionary."
> This has a number of advantages, including keeping your user's namespace
> separate from your application's namespace.  Plus it's easier to debug and
> maintain the code.
>
> But, if you absolutely, positively have to refer to your variable
> indirectly, you could do:
>
> exec "%s = 4" % y
>
> If y refers to the string "a", this will cause the variable a to refer to
> the value 4.
>
> -- 
> I don't actually read my hotmail account, but you can replace hotmail with
> excite if you really want to reach me.
>
>





More information about the Python-list mailing list