I'm not sure. I think scoping would screw you up. First off, there's a small reason right away why it wouldn't work. You'd have to quote your argument to debugExpr, as in, say, debugExpr('2 times 3'). I did a little test at the Python prompt and the results didn't look good for faking this macro with eval:
def foo(x):
return 2 times (x + 3)
> foo(1)
8
(not a full version of debugExpr, but enough to test:)
def debugExpr(expr):
print "Expr is " + expr
return eval(expr)
def bar(x):
return 2 times debugExpr('x + 3')
> bar(1)
Expr is x + 3
Traceback (most recent call last):
File "", line 1, in ?
File "", line 2, in bar
File "", line 3, in debugExpr
File "", line 0, in ?
NameError: name 'x' is not defined
PS: I couldn't use the asterisk symbol in the post, so I used 'times' instead.
def foo(x): return 2 times (x + 3)
> foo(1)
8
(not a full version of debugExpr, but enough to test:)
def debugExpr(expr): print "Expr is " + expr return eval(expr)
def bar(x): return 2 times debugExpr('x + 3')
> bar(1)
Expr is x + 3
Traceback (most recent call last):
File "", line 1, in ?
File "", line 2, in bar
File "", line 3, in debugExpr
File "", line 0, in ?
NameError: name 'x' is not defined
PS: I couldn't use the asterisk symbol in the post, so I used 'times' instead.