Using eval with substitutions
- From: abhishek@xxxxxxxxxxxxxxxx
- Date: 31 Aug 2006 04:15:20 -0700
7a,b=3,4
x="a+b"
eval(x)
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,
10eval(y.replace("x",str(eval(x))))
but this becomes unwieldy if I have
and so on, because the replacements have to be done in exactly thew="y*b"
right order. Is there a better way?
Thanks,
Abhishek
.
- Follow-Ups:
- Re: Using eval with substitutions
- From: Fredrik Lundh
- Re: Using eval with substitutions
- Prev by Date: Re: How to avoid a warning message box when sending email via Outlook
- Next by Date: Re: Using eval with substitutions
- Previous by thread: wxNotebook color change
- Next by thread: Re: Using eval with substitutions
- Index(es):