[IPython-user] Hooking into the autocall displayer

Fernando Perez fperez.net@gmail....
Mon Sep 17 01:24:07 CDT 2007


On 9/16/07, Tom Denniston <tom.denniston@alum.dartmouth.org> wrote:
> When I use autocall in IPython one of the awesome things about it, is
> that it prints this green ------> with what it translated my code to.
> For example:
>
> In [1]: map str, [1,2,3]
> ------> map(str, [1,2,3])
> Out[1]: ['1', '2', '3']
>
> I wanted to hook into the function that does this printing because I
> have some custom translations taht i do using the result_display hook.
>  I print -------> plus my translation but then I end up with a line
> that is:
>
> Out[1]: -------> my translated result
>
> What i really want is
> ------> my translated result
>
> I could do it myself with some messy teminal escape sequence
> manipulation but it would be much cleaner if it is possible to call
> the function that IPython is using.
>
> Does anyone have any idea how to do this?

The routine that does this is auto_rewrite, in Prompts.py:

http://projects.scipy.org/ipython/ipython/browser/ipython/trunk/IPython/Prompts.py#L348

You could start testing out your idea with a quick and dirty
monkeypatch of that method.  If it works, a proper API could be
exposed.

Cheers,

f


More information about the IPython-user mailing list