How do I do this? (eval() on the left hand side)
It's me
itsme at yahoo.com
Tue Dec 7 16:12:24 EST 2004
"Caleb Hattingh" <caleb1 at telkomsa.net> wrote in message
news:opsin754im1js0xs at news.telkomsa.net...
> Hi It's me
>
> >
> > a = 3
> > y = "a"
> > print eval(y)
> >
>
> To get 'a' to be 4 here, you would say
>
> a = 4
>
Obviously but that's not what I wish to do.
> I am not sure why you would want to do otherwise? Perhaps you could
> sketch out a little more about what you are trying to do? That would help
> a lot. Are you aiming for something like pointer emulation with simple
> datatypes?
>
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).
> Thanks
> Caleb
More information about the Python-list
mailing list