[IPython-User] change prompt dynamically

Fernando Perez fperez.net@gmail....
Wed Sep 14 19:22:45 CDT 2011

On Wed, Sep 14, 2011 at 11:40 AM, Kuznetsov Valentin <vkuznet@gmail.com> wrote:
> In ipython version < 0.11 I was able to dynamically change prompt into ipython session as simple as
> IP = IPython.ipapi.get()
> def set_prompt(in1):
>    """Define shell prompt"""
>    ip = IP.user_ns['__IP']
>    prompt = getattr(ip.outputcache, 'prompt1')
>    prompt.p_template = '\C_LightBlue[\C_LightCyan%s\C_LightBlue]|\#> ' % in1
>    prompt.set_p_str()

You can do it in almost the same way, it's just that the attributes
have moved around:

ip = get_ipython()
ip.displayhook.prompt1.p_template = 'your new prompt template'

Now, please note that as Thomas mentioned, we're in the middle of
refactoring the prompt system, that's one of the things we just didn't
manage to finish before 0.11 was released.  So this may change again
for 0.12 or 0.13 as soon as we complete the prompt system redesign.

Sorry for the hassle, but it's just a piece of the code that does need
refactoring, and we simply didn't have the manpower to do it all
before releasing 0.11.



More information about the IPython-User mailing list