[IPython-user] Prompt expressions
m.scarpa at uva.nl
Fri Jun 16 05:04:58 CDT 2006
On Thu, Jun 15, 2006 at 10:13:04PM +0300, Ville Vainio wrote:
> On 6/15/06, Ville Vainio <vivainio at gmail.com> wrote:
> >On 6/14/06, Fernando Perez <fperez.net at gmail.com> wrote:
> >> On 6/13/06, Michael Scarpa <m.scarpa at uva.nl> wrote:
> >> > Dear IPython users,
> >> >
> >> > Am I doing something wrong? Is this a feature of IPython? And most
> >> > importantly (to me): how can I avoid this? Of course I could keep
> >> > flipping a bit in the method I want to have executed when the prompt is
> >> > put on screen, but that would seem a rather nasty hack.
> >> It's a bug, I just filed a ticket for it:
> >> http://projects.scipy.org/ipython/ipython/ticket/69
> >> In the meantime, a state bit hack will do, ugly as it may be.
> >I will fix this, but I think I'll do it by exposing the prompt
> >calculation as a hook to expose this functionality in a predictable
> >and simple manner (and thus squat 2 flies at the same time).
> Done in SVN (rev 1365), here's an example:
> In : pycat myprompt.py
> import os
> from IPython import ipapi
> def prompt_hook(self, cont):
> if cont: return 'cont..'
> return os.getcwd() + " >"
> In : import myprompt
> /home/ville/ipython >1 + (
> cont..2 +
> Out: 6
> /home/ville/ipython >
Looks nice, but since it's all moving to hooks anyway: The reason why I
am using prompt expressions is that I have a function that I want to be
executed every time *after* the execution of the last input. Since
IPython outputs the input-prompt after the execution, I simply tucked my
function call into the prompt. Now, is there (or is there going to be)
a hook to do this in a more elegant way than re-implementing the
standard IPython input-prompt-hook with the added function call? In the
end I don't need to change the prompt, but tho have my function be
called after the processing of the last user input.
More information about the IPython-user