[Python-ideas] History stepping in interactive session?

Terry Reedy tjreedy at udel.edu
Fri Oct 5 21:18:21 CEST 2012


On 10/5/2012 8:43 AM, Oscar Benjamin wrote:
> On 5 October 2012 10:27, Andy Buckley <andy at insectnation.org> wrote:

>> 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.

Using Windows for a couple of decades, I am not spoiled by bash ;-).

Idle lets me directly click on a previous statement and hit enter to 
make it the current statement. Edit if desired and hit enter again to 
execute again in the current workspace. But I agree with Oscar that even 
a few lines are worth a temporary script file.

> 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.

In Idle, I click File - Recent files - .../tem.py (in my misc. files 
directory) to open an edit window, which I leave open all day. Running 
from the edit window does restart the workspace, so one would have to 
cut and paste to not restart. I seldom want to re-run multiple lines 
without restarting.

If I want to keep the 'temporary' code, saving under a different name is 
easy.

-- 
Terry Jan Reedy




More information about the Python-ideas mailing list