<p dir="ltr"><br>
On 3 Jun 2013 09:04, "Steven D'Aprano" <<a href="mailto:steve%2Bcomp.lang.python@pearwood.info">steve+comp.lang.python@pearwood.info</a>> wrote:<br>
><br>
> The sys module defines two hooks that are used in the interactive<br>
> interpreter:<br>
><br>
> * sys.displayhook(value) gets called with the result of evaluating the<br>
> line when you press ENTER;<br>
><br>
> * sys.excepthook(type, value, traceback) gets called with the details of<br>
> the exception when your line raises an exception.<br>
><br>
> Is there a way to hook into the interactive interpreter *before* it is<br>
> evaluated? That is, if I type "len([])" at the prompt and hit ENTER, I<br>
> want a hook that runs before len([]) is evaluated to 0, so that I get the<br>
> string "len([])".<br>
></p>
<p dir="ltr">I don't know whether that is possible, but you could recreate the repl. This page seems to have good resources for that: <a href="http://stackoverflow.com/questions/1395913/python-drop-into-repl-read-eval-print-loop">http://stackoverflow.com/questions/1395913/python-drop-into-repl-read-eval-print-loop</a></p>
<p dir="ltr">A trace function could also work. See docs for sys.settrace. The source code for the python GOTO module is a good example of its usage.<br>
</p>