[IPython-user] Prompt expressions

Ville Vainio vivainio at gmail.com
Thu Jun 15 14:46:21 CDT 2006


On 6/15/06, Walter Dörwald <walter at livinglogic.de> wrote:

> What about the
> output prompt?

Output prompts now (rev 1366) work through generate_output_prompt
hook, an example:

[~/ipython]|1> pycat myp
myprompt.py   myprompt.pyc  myprompt.py~
[~/ipython]|1> pycat myprompt.py
import os
from IPython import ipapi
def prompt_hook(self, cont):
    print "calculating prompt",cont
    if cont: return 'cont..'
    return os.getcwd() + " >"

import time
def output_prompt_hook(self):
    print "calc output prompt"
    return "%d ->" % time.time()

ipapi.get().set_hook('generate_prompt',prompt_hook)
ipapi.get().set_hook('generate_output_prompt',output_prompt_hook)

[~/ipython]|2> import myprompt
calculating prompt False
/home/ville/ipython >1+2
calc output prompt
1150375369 ->3
calculating prompt False
/home/ville/ipython >1+2
calc output prompt
1150375374 ->3
calculating prompt False
/home/ville/ipython >

-- 
Ville Vainio - vivainio.googlepages.com
vainio.blogspot.com - g[mail | talk]='vivainio'




More information about the IPython-user mailing list