In Chapter 2 we looked at the basics of using the IPython shell and Jupyter notebook. In this chapter, we explore some deeper functionality in the IPython system that can either be used from the console or within Jupyter.
IPython maintains a small on-disk database containing the text of each command that you execute. This serves various purposes:
Searching, completing, and executing previously executed commands with minimal typing
Persisting the command history between sessions
Logging the input/output history to a file
These features are more useful in the shell than in the notebook, since the notebook by design keeps a log of the input and output in each code cell.
The IPython shell lets you search and execute previous code or other commands.
This is useful, as you may often find yourself repeating the same
commands, such as a
%run command or some
other code snippet. Suppose you had run:
In: %run first/second/third/data_script.py
and then explored the results of the script (assuming it ran
successfully) only to find that you made an incorrect calculation. After
figuring out the problem and modifying
data_script.py, you can start typing a few letters
%run command and then press either
the Ctrl-P key combination or the up arrow key. This will search the command history for the first prior command matching the letters you typed. Pressing either Ctrl-P or the up arrow key ...