[IPython-user] Insert a command (text) automatically at the prompt
Yann Le Du
yledu@free...
Sun Sep 28 16:46:16 CDT 2008
On Fri, 26 Sep 2008, Ville M. Vainio wrote:
> On Fri, Sep 26, 2008 at 5:57 PM, Yann Le Du <yledu@free.fr> wrote:
>
>> Is it possible to switch a flag on, and then have some text automatically
>> added at the beginning of each command line when pressing the "Enter" key
>> ? Says something like this
>
> Investigate:
>
> _ip.set_next_input
>
> pre_prompt_hook
>
> Too busy for ready-made answer now ;-)
Thanks a lot Ville : with your hints, I found how to do it, but I didn't
manage to remove the inserted command, i.e. remove the hook. Here's what I
did :
def foo_pre_prompt_hook(self):
ip = IPython.ipapi.get()
ip.set_next_input("foo: ")
def qsetPrompt(stv = True):
ip = IPython.ipapi.get()
if stv:
ip.set_hook('pre_prompt_hook',foo_pre_prompt_hook)
else:
pass # What do I need to put here to remove the hook ?
--
Yann Le Du
More information about the IPython-user
mailing list