- Original Message -
From: "Carl Banks" <[EMAIL PROTECTED]>
Newsgroups: comp.lang.python
To:
Sent: Saturday, September 02, 2006 6:33 AM
Subject: Re: Using eval with substitutions
> [EMAIL PROTECTED] wrote:
> > >>> a,b=3,4
> > >>> x=&quo
[EMAIL PROTECTED] wrote:
> >>> 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 beco
Thanks very much for all your suggestions - Peter, Duncan and Frederic.
It was a great help.
Incidentally the question arose while I was trying to solve the 2-nots
problem,
http://www.inwap.com/pdp10/hbaker/hakmem/boolean.html#item19
Part of my program takes a set of boolean expressions in 3 vari
xample you'll find SE here:
http://cheeseshop.python.org/pypi/SE/2.2%20beta
Regards
Frederic
----- Original Message -
From: <[EMAIL PROTECTED]>
Newsgroups: comp.lang.python
To:
Sent: Thursday, August 31, 2006 1:15 PM
Subject: Using eval with substitutions
> >>> a,b=3
[EMAIL PROTECTED] wrote:
> 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 s
[EMAIL PROTECTED] wrote:
> 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 h
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
namesp
[EMAIL PROTECTED] wrote:
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 become
>>> 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, bec