[IPython-user] Prompt

Fernando.Perez at colorado.edu Fernando.Perez at colorado.edu
Wed Mar 16 04:44:16 CST 2005

Quoting Frédéric Mantegazza <mantegazza at ill.fr>:

> Yes, this is OK for me ! As I said, I want to use the prompt as a little
> status bar. So I only need to put 2 or 3 values which will be taken and
> refreshed from my app. If your dict could be rebinded to a user dict, it
> should work.

As it turns out, IPython actually already did have support for dynamic prompts. 
We just didn't know it :)  I've added this to the manual:

IPython supports the evaluation of arbitrary expressions in your prompt string.
The prompt strings are evaluated through the syntax of PEP 215, but basically
you can use $x.y to expand the value of x.y, and for more complicated
expressions you can use braces: ${foo()+x} will call function foo and add to it
the value of x, before putting the result into your prompt. For example, using
prompt_in1 '${commands.getoutput("uptime")}\nIn [\#]: '
will print the result of the uptime command on each prompt (assuming the
commands module has been imported in your ipythonrc file).

Note that in 0.6.12, the above is actually extremely brittle, and it doesn't
really work with the user interactive namespace.  But a few small fixes, now in
CVS, seem to make it work quite well.  Give the CVS version a try, and let me
know if this is enough for your needs.



More information about the IPython-user mailing list