Re: Using eval with substitutions
- From: Fredrik Lundh <fredrik@xxxxxxxxxxxxxx>
- Date: Thu, 31 Aug 2006 13:32:07 +0200
abhishek@xxxxxxxxxxxxxxxx wrote:
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 haveand so on, because the replacements have to be done in exactly thew="y*b"
right order. Is there a better way?
instead of
x = "a+b"
do
x = "a+b"
x = eval(x)
or
x = eval("a+b")
(I'm afraid I don't really understand the point of your examples; what is it you're really trying to do here ?)
</F>
.
- Follow-Ups:
- Re: Using eval with substitutions
- From: abhishek
- Re: Using eval with substitutions
- References:
- Using eval with substitutions
- From: abhishek
- Using eval with substitutions
- Prev by Date: Using eval with substitutions
- Next by Date: Re: Broadcast server
- Previous by thread: Using eval with substitutions
- Next by thread: Re: Using eval with substitutions
- Index(es):