Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #28074

Re: How to program test(expr) ?

From Terry Reedy <tjreedy@udel.edu>
Subject Re: How to program test(expr) ?
Date 2012-08-29 17:35 -0400
References <franck-E4DC28.17040529082012@news.free.fr>
Newsgroups comp.lang.python
Message-ID <mailman.3944.1346276175.4697.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

How to program test(expr) ? Franck Ditter <franck@ditter.org> - 2012-08-29 17:04 +0200
  Re: How to program test(expr) ? Terry Reedy <tjreedy@udel.edu> - 2012-08-29 17:35 -0400
  Re: How to program test(expr) ? Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2012-08-30 09:33 +0200

csiph-web