Module: history

Inheritance diagram for IPython.history:

History related magics and functionality



class IPython.history.ShadowHist(db)



Alternate name for %history.


Print input history (_i<n> variables), with most recent last.

%history -> print at most 40 inputs (some may be multi-line)%history n -> print at most n inputs%history n1 n2 -> print inputs between n1 and n2 (n2 not included)

Each input’s number <n> is shown, and is accessible as the automatically generated variable _i<n>. Multi-line statements are printed starting at a new line for easy copy/paste.


-n: do NOT print line numbers. This is useful if you want to get a printout of many lines which can be directly pasted into a text editor.

This feature is only available if numbered prompts are in use.

-t: (default) print the ‘translated’ history, as IPython understands it. IPython filters your input and converts it all into valid Python source before executing it (things like magics or aliases are turned into function calls, for example). With this option, you’ll see the native history instead of the user-entered version: ‘%cd /’ will be seen as ‘_ip.magic(“%cd /”)’ instead of ‘%cd /’.

-r: print the ‘raw’ history, i.e. the actual commands you typed.

-g: treat the arg as a pattern to grep for in (full) history. This includes the “shadow history” (almost all commands ever written). Use ‘%hist -g’ to show full shadow history (may be very long). In shadow history, every index nuwber starts with 0.

-f FILENAME: instead of printing the output to the screen, redirect it to
the given file. The file is always overwritten, though IPython asks for confirmation first if it already exists.

Repeat a command, or get command to input line for editing

  • %rep (no arguments):

Place a string version of last computation result (stored in the special ‘_’ variable) to the next input prompt. Allows you to create elaborate command lines without using copy-paste:

$ l = ["hei", "vaan"]       
$ "".join(l)        
==> heivaan        
$ %rep        
$ heivaan_ <== cursor blinking    

%rep 45

Place history line 45 to next input prompt. Use %hist to find out the number.

%rep 1-4 6-7 3

Repeat the specified lines immediately. Input slice syntax is the same as in %macro and %save.

%rep foo

Place the most recent line that has the substring “foo” to next input. (e.g. ‘svn ci -m foobar’).

Table Of Contents

Previous topic


Next topic


This Page