How to program test(expr) ?
Terry Reedy
tjreedy at udel.edu
Wed Aug 29 17:35:20 EDT 2012
On 8/29/2012 11:04 AM, Franck Ditter wrote:
> 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 ?
No, not as Python is delivered.
> # 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 ?
It might be possible to write an IDLE extension that would 'process'
interactive input looking for (untested) re pattern something like
'test\((.*)\)'. Given a match, it prints the captured .* part and passes
it on to the Python interpreter, and prefixes output with '-->'.
(I have not yet looked at how to write extensions.)
--
Terry Jan Reedy
More information about the Python-list
mailing list