>>> a,b=3,4
>>> x="a+b"
>>> eval(x)
7
>>> y="x+a"

Now I want to evaluate y by substituting for the evaluated value of x.
eval(y) will try to add "a+b" to 3 and return an error. I could do
this,
>>> eval(y.replace("x",str(eval(x))))
10

but this becomes unwieldy if I have
>>> w="y*b"
and so on, because the replacements have to be done in exactly the
right order. Is there a better way?

Thanks,
Abhishek

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to