IPython - Command History

Card Puncher Data Processing


Command history management



By default, the history file is named .ipython/profile_name/history.sqlite


  • up- and down-arrow keys
  • or Ctrl-p and Ctrl-n
  • Ctrl-r

Variable In and out

  • Input and output history are kept in variables called In and Out, keyed by the prompt numbers, e.g. In[4].
Type:        list
String form: ['', "print('Hello IPython')", '21 * 2', "def say_hello(name):\n    print('Hello {name}'.format(n <...> = range(10000)', 'max(x)')", "get_ipython().magic('lsmagic')", "get_ipython().magic('pinfo In')"]
Length:      12
list() -> new empty list
list(iterable) -> new list initialized from iterable's items

Shortcut variable

  • The last three objects in output history are also kept in variables named _, and _.


  • %history magic function can examine past input and output.
  • %edit, %rerun, %recall, %macro, %save and %pastebin can use history input:
%pastebin 3 18-20 ~1/1-5

This will take line 3 and lines 18 to 20 from the current session, and lines 1-5 from the previous session.

Documentation / Reference

Discover More
Card Puncher Data Processing
IPython (Interactive Shell)

command description ? Introduction and overview of IPython’s features. %quickref Quick reference help Python’s own help system. object? Details ‘object’, use ‘object??’ for extra...
Card Puncher Data Processing
IPython - Command

IPython - Command
Card Puncher Data Processing
iPython - Editor

%edit magic - IPython opens an empty editor with a temporary file, and it returns the contents of your editing session as a string variable. %edit -p - open an editor with the same data as the last...

Share this page:
Follow us:
Task Runner