Re: Using eval with substitutions
- From: abhishek@xxxxxxxxxxxxxxxx
- Date: 31 Aug 2006 05:28:05 -0700
Fredrik Lundh wrote:
(I'm afraid I don't really understand the point of your examples; what
is it you're really trying to do here ?)
A function is passed a bunch of string expressions like,
x = "a+b"
y= "x*a"
z= "x+y"
where a and b are assumed to have been assigned values in the local
namespace. Now I have to evaluate another string such as,
"z+y+x"
So as you say, I could do:
x=eval(x), y=eval(y), z=eval(z) and finally eval("z+y+x") but the
problem is that the initial strings are in no particular order, so I
don't know the sequence in which to perform the first 3 evaluations. I
was wondering if there was a simple way to 'pattern-match' so that the
required substitutions like z->x+y->x+x*a->(a+b)+(a+b)*a could be done
automatically.
I apologise if this is still not quite clear.
Abhishek
.
- Follow-Ups:
- Re: Using eval with substitutions
- From: Duncan Booth
- Re: Using eval with substitutions
- From: Peter Otten
- Re: Using eval with substitutions
- References:
- Using eval with substitutions
- From: abhishek
- Re: Using eval with substitutions
- From: Fredrik Lundh
- Using eval with substitutions
- Prev by Date: Re: [ANN] ratfun-2.3 Polynomials and Rational Functions
- Next by Date: Re: wxNotebook color change
- Previous by thread: Re: Using eval with substitutions
- Next by thread: Re: Using eval with substitutions
- Index(es):
Relevant Pages
|