How to program test(expr) ?

Franck Ditter franck at ditter.org
Wed Aug 29 11:04:05 EDT 2012


Hi !
I use Python 3.2.3 + Idle.
Is it possible to program test(e) which takes
an expression e and whose execution produces
at the toplevel an echo of e and the effects
and result of its evaluation ?

# file foo.py
def foo(x) :
  print('x =',x)
  return x+1

test(foo(5))

# RUN !

# produces at the toplevel :
? foo(5)
x = 5
--> 6

I know I could put the expression e within a string, but
is it possible to avoid the string, like a Lisp macro ?

Thanks.

    franck



More information about the Python-list mailing list