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


Groups > comp.lang.python > #46789

Re: Interactive interpreter hooks

From Terry Jan Reedy <tjreedy@udel.edu>
Subject Re: Interactive interpreter hooks
Date 2013-06-03 09:03 -0400
References <51ac4bfc$0$11118$c3e8da3@news.astraweb.com>
Newsgroups comp.lang.python
Message-ID <mailman.2595.1370264612.3114.python-list@python.org> (permalink)

Show all headers | View raw


On 6/3/2013 3:55 AM, Steven D'Aprano wrote:
> The sys module defines two hooks that are used in the interactive
> interpreter:
>
> * sys.displayhook(value) gets called with the result of evaluating the
> line when you press ENTER;
>
> * sys.excepthook(type, value, traceback) gets called with the details of
> the exception when your line raises an exception.
>
> Is there a way to hook into the interactive interpreter *before* it is
> evaluated? That is, if I type "len([])" at the prompt and hit ENTER, I
> want a hook that runs before len([]) is evaluated to 0, so that I get the
> string "len([])".

You have not said what you are actually trying to do, but you could 
definitely modify Idle to do something with user input before it sends 
it to the user process.



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


Thread

Interactive interpreter hooks Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-03 07:55 +0000
  Re: Interactive interpreter hooks Fábio Santos <fabiosantosart@gmail.com> - 2013-06-03 10:00 +0100
  Re: Interactive interpreter hooks Terry Jan Reedy <tjreedy@udel.edu> - 2013-06-03 09:03 -0400
  Re: Interactive interpreter hooks Robert Kern <robert.kern@gmail.com> - 2013-06-03 14:19 +0100

csiph-web