In ipython, we can use
_ih[32:39]
To show history lines between 32 and 39. How can I directly execute these history lines?
You start IPython by typing “ipython” in your terminal. $ ipython Python 2.7. 2 (default, Jun 20 2012, 16:23:33) Type "copyright", "credits" or "license" for more information. IPython 0.13.
Use '%hist -g' to show full saved history (may be very long). get the last n lines from all sessions. Specify n as a single arg, or the default is the last 10 lines.
The easiest way is to run easy_install ipython[all] as an administrator (start button, type cmd , shift+right click on “cmd.exe” and select “Run as administrator”). This installs the latest stable version of IPython including the main required and optional dependencies.
IPython bridges this gap, and gives you a syntax for executing shell commands directly from within the IPython terminal. The magic happens with the exclamation point: anything appearing after ! on a line will be executed not by the Python kernel, but by the system command-line.
You can execute code from previous sessions with %recall
. See %recall
documentation here.
#Execute all code from previous session. %recall ~1/ #Execute all code from two sessions previous the current session. %recall ~2/ #Execute lines 1 to 5 from previous session. %recall ~1/1-5
I use the list notation:
exec In[34:36]
also, if you use the edit function to edit a chunk, the Out list will have your code in it, so:
exec Out[35]
And my favorite:
edit In[34:38]
because I am a fat-fingered slob who can rarely get it right on the first try.
On recent versions of iPython you use the rerun magic-comand:
%rerun 32:39
Documentation on that command: http://ipython.readthedocs.io/en/stable/interactive/magics.html#magic-rerun
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With