[Python-ideas] History stepping in interactive session?
Oscar Benjamin
oscar.j.benjamin at gmail.com
Fri Oct 5 14:43:00 CEST 2012
On 5 October 2012 10:27, Andy Buckley <andy at insectnation.org> wrote:
> A couple of weeks ago I posted a question on superuser.com about whether
> there is a way to get the same *very* convenient
> stepping-through-command-history behaviour in an interactive Python
> interpreter session as is possible in (at least) the bash shell with the
> Ctrl-o keybinding:
>
> http://superuser.com/questions/477997/key-binding-to-interactively-execute-commands-from-python-interpreter-history-in
>
> I was spurred to ask this question by a painful development experience
> full of Up Up Up Up Up Enter Up Up Up Up Up Enter ... keypresses to
> repeat a previous set of Python commands/statements that weren't worth
> putting in a script file, or which I wanted to make very minor changes
> to on each iteration.
As soon as I find myself doing this I quit the interpreter and start
ipython. The feature that ipython has that makes what you are doing
much easier is the magic %edit command. Just type
In [1]: edit tmp.py
and your favourite editor will open up allowing you to write/edit some
code. When you close the editor, ipython will run the code from tmp.py
within the interactive session (as if you had typed it in directly).
If you want to rerun that code with modifications just type 'edit
tmp.py' again and you can make the modifications within your editor.
Oscar
More information about the Python-ideas
mailing list