Skip to content

Instantly share code, notes, and snippets.

@damontallen
Last active December 29, 2020 02:39
Show Gist options
  • Save damontallen/5675210 to your computer and use it in GitHub Desktop.
Save damontallen/5675210 to your computer and use it in GitHub Desktop.
Less brittle HTML table converter of the quickref text.
<table border="1" cellpadding="3" cellspacing="0" style="border:1px solid black;border-collapse:collapse;">
<tr><td style="background-color:lightBlue;" colspan="2"; ><b>IPython -- An enhanced Interactive Python - Quick Reference Card</b></td></tr>
<tr><td colspan="2"; > </td></tr>
<tr><td style="border-bottom: 1px solid transparent;"> obj?, obj?? </td><td style="border-bottom: 1px solid transparent;"> Get help, or more help for object (also works as</tr>
<tr><td style="border-top: 1px solid transparent;"> </td><td style="border-top: 1px solid transparent;"> ?obj, ??obj).</tr>
<tr><td>?foo.*abc*</td><td> List names in 'foo' containing 'abc' in them.</td></tr>
<tr><td>%magic</td><td> Information about IPython's 'magic' % functions.</td></tr>
<tr><td colspan="2"; > </td></tr>
<tr><td colspan="2"; style="border-bottom: 1px solid transparent;">Magic functions are prefixed by % or %%, and typically take their arguments</td></tr>
<tr><td colspan="2"; style="border-top: 1px solid transparent; border-bottom: 1px solid transparent;">without parentheses, quotes or even commas for convenience. Line magics take a</td></tr>
<tr><td colspan="2"; style="border-top: 1px solid transparent;">single % and cell magics are prefixed with two %%.</td></tr>
<tr><td colspan="2"; > </td></tr>
<tr><td style="background-color:#D5E0C5;" colspan="2"; ><b>Example magic function calls:</b></td></tr>
<tr><td colspan="2"; > </td></tr>
<tr><td>%alias d ls -F</td><td> 'd' is now an alias for 'ls -F'</td></tr>
<tr><td>alias d ls -F</td><td> Works if 'alias' not a python name</td></tr>
<tr><td>alist = %alias</td><td> Get list of aliases to 'alist'</td></tr>
<tr><td>cd /usr/share</td><td> Obvious. cd -&#60tab&#62 to choose from visited dirs.</td></tr>
<tr><td>%cd??</td><td> See help AND source for magic %cd</td></tr>
<tr><td>%timeit x=10</td><td> time the 'x=10' statement with high precision.</td></tr>
<tr><td style="border-bottom: 1px solid transparent;"> %%timeit x=2**100 </td><td style="border-bottom: 1px solid transparent;"> time 'x*100' with a setup of 'x=2**100'; setup code is not</tr>
<tr><td style="border-top: 1px solid transparent;"> x**100 </td><td style="border-top: 1px solid transparent;"> counted. This is an example of a cell magic.</tr>
<tr><td colspan="2"; > </td></tr>
<tr><td style="background-color:#D5E0C5;" colspan="2"; ><b>System commands:</b></td></tr>
<tr><td colspan="2"; > </td></tr>
<tr><td>!cp a.txt b/</td><td> System command escape, calls os.system()</td></tr>
<tr><td>cp a.txt b/</td><td> after %rehashx, most system commands work without !</td></tr>
<tr><td>cp ${f}.txt $bar</td><td> Variable expansion in magics and system commands</td></tr>
<tr><td>files = !ls /usr</td><td> Capture sytem command output</td></tr>
<tr><td>files.s, files.l, files.n</td><td> "a b c", ['a','b','c'], 'a\nb\nc'</td></tr>
<tr><td colspan="2"; > </td></tr>
<tr><td style="background-color:#D5E0C5;" colspan="2"; ><b>History:</b></td></tr>
<tr><td colspan="2"; > </td></tr>
<tr><td>_i, _ii, _iii</td><td> Previous, next previous, next next previous input</td></tr>
<tr><td>_i4, _ih[2:5]</td><td> Input history line 4, lines 2-4</td></tr>
<tr><td>exec _i81</td><td> Execute input history line #81 again</td></tr>
<tr><td>%rep 81</td><td> Edit input history line #81</td></tr>
<tr><td>_, __, ___</td><td> previous, next previous, next next previous output</td></tr>
<tr><td>_dh</td><td> Directory history</td></tr>
<tr><td>_oh</td><td> Output history</td></tr>
<tr><td>%hist</td><td> Command history. '%hist -g foo' search history for 'foo'</td></tr>
<tr><td colspan="2"; > </td></tr>
<tr><td style="background-color:#D5E0C5;" colspan="2"; ><b>Autocall:</b></td></tr>
<tr><td colspan="2"; > </td></tr>
<tr><td>f 1,2</td><td> f(1,2) # Off by default, enable with %autocall magic.</td></tr>
<tr><td>/f 1,2</td><td> f(1,2) (forced autoparen)</td></tr>
<tr><td>,f 1 2</td><td> f("1","2")</td></tr>
<tr><td>;f 1 2</td><td> f("1 2")</td></tr>
<tr><td colspan="2"; > </td></tr>
<tr><td colspan="2"; style="border-bottom: 1px solid transparent;">Remember: TAB completion works in many contexts, not just file names</td></tr>
<tr><td colspan="2"; style="border-top: 1px solid transparent;">or python names.</td></tr>
<tr><td colspan="2"; > </td></tr>
<tr><td style="background-color:#D5E0C5;" colspan="2"; ><b>The following magic functions are currently available:</b></td></tr>
<tr><td colspan="2"; > </td></tr>
<tr><td>%alias</td><td> Define an alias for a system command.</td></tr>
<tr><td>%alias_magic</td><td> %alias_magic [-l] [-c] name target</td></tr>
<tr><td>%autocall</td><td> Make functions callable without having to type parentheses.</td></tr>
<tr><td>%automagic</td><td> Make magic functions callable without having to type the initial %.</td></tr>
<tr><td>%bookmark</td><td> Manage IPython's bookmark system.</td></tr>
<tr><td>%cd</td><td> Change the current working directory.</td></tr>
<tr><td>%clear</td><td> Clear the terminal.</td></tr>
<tr><td>%colors</td><td> Switch color scheme for prompts, info system and exception handlers.</td></tr>
<tr><td>%config</td><td> configure IPython</td></tr>
<tr><td>%connect_info</td><td> Print information for connecting other clients to this kernel</td></tr>
<tr><td>%debug</td><td> Activate the interactive debugger in post-mortem mode.</td></tr>
<tr><td>%dhist</td><td> Print your history of visited directories.</td></tr>
<tr><td>%dirs</td><td> Return the current directory stack.</td></tr>
<tr><td>%doctest_mode</td><td> Toggle doctest mode on and off.</td></tr>
<tr><td>%ed</td><td> Alias for `%edit`.</td></tr>
<tr><td>%edit</td><td> Bring up an editor and execute the resulting code.</td></tr>
<tr><td>%env</td><td> List environment variables.</td></tr>
<tr><td>%gui</td><td> Enable or disable IPython GUI event loop integration.</td></tr>
<tr><td>%hist</td><td> Print input history (_i&#60n&#62 variables), with most recent last.</td></tr>
<tr><td>%history</td><td> Print input history (_i&#60n&#62 variables), with most recent last.</td></tr>
<tr><td>%install_default_config</td><td> %install_default_config has been deprecated.</td></tr>
<tr><td>%install_ext</td><td> Download and install an extension from a URL, e.g.::</td></tr>
<tr><td>%install_profiles</td><td> %install_profiles has been deprecated.</td></tr>
<tr><td>%killbgscripts</td><td> Kill all BG processes started by %%script and its family.</td></tr>
<tr><td>%less</td><td> Show a file through the pager.</td></tr>
<tr><td>%load</td><td> Load code into the current frontend.</td></tr>
<tr><td>%load_ext</td><td> Load an IPython extension by its module name.</td></tr>
<tr><td>%loadpy</td><td> Alias of `%load`</td></tr>
<tr><td>%logoff</td><td> Temporarily stop logging.</td></tr>
<tr><td>%logon</td><td> Restart logging.</td></tr>
<tr><td>%logstart</td><td> Start logging anywhere in a session.</td></tr>
<tr><td>%logstate</td><td> Print the status of the logging system.</td></tr>
<tr><td>%logstop</td><td> Fully stop logging and close log file.</td></tr>
<tr><td>%lsmagic</td><td> List currently available magic functions.</td></tr>
<tr><td>%macro</td><td> Define a macro for future re-execution. It accepts ranges of history,</td></tr>
<tr><td>%magic</td><td> Print information about the magic function system.</td></tr>
<tr><td>%man</td><td> Find the man page for the given command and display in pager.</td></tr>
<tr><td>%more</td><td> Show a file through the pager.</td></tr>
<tr><td>%notebook</td><td> %notebook [-e] [-f FORMAT] filename</td></tr>
<tr><td>%page</td><td> Pretty print the object and display it through a pager.</td></tr>
<tr><td>%pastebin</td><td> Upload code to Github's Gist paste bin, returning the URL.</td></tr>
<tr><td>%pdb</td><td> Control the automatic calling of the pdb interactive debugger.</td></tr>
<tr><td>%pdef</td><td> Print the definition header for any callable object.</td></tr>
<tr><td>%pdoc</td><td> Print the docstring for an object.</td></tr>
<tr><td>%pfile</td><td> Print (or run through pager) the file where an object is defined.</td></tr>
<tr><td>%pinfo</td><td> Provide detailed information about an object.</td></tr>
<tr><td>%pinfo2</td><td> Provide extra detailed information about an object.</td></tr>
<tr><td>%popd</td><td> Change to directory popped off the top of the stack.</td></tr>
<tr><td>%pprint</td><td> Toggle pretty printing on/off.</td></tr>
<tr><td>%precision</td><td> Set floating point precision for pretty printing.</td></tr>
<tr><td>%profile</td><td> Print your currently active IPython profile.</td></tr>
<tr><td>%prun</td><td> Run a statement through the python code profiler.</td></tr>
<tr><td>%psearch</td><td> Search for object in namespaces by wildcard.</td></tr>
<tr><td>%psource</td><td> Print (or run through pager) the source code for an object.</td></tr>
<tr><td>%pushd</td><td> Place the current dir on stack and change directory.</td></tr>
<tr><td>%pwd</td><td> Return the current working directory path.</td></tr>
<tr><td>%pycat</td><td> Show a syntax-highlighted file through a pager.</td></tr>
<tr><td>%pylab</td><td> Load numpy and matplotlib to work interactively.</td></tr>
<tr><td>%qtconsole</td><td> Open a qtconsole connected to this kernel.</td></tr>
<tr><td>%quickref</td><td> Show a quick reference sheet</td></tr>
<tr><td>%quickref_file</td><td> Save a quick reference sheet on disk</td></tr>
<tr><td>%recall</td><td> Repeat a command, or get command to input line for editing.</td></tr>
<tr><td>%rehashx</td><td> Update the alias table with all executable files in $PATH.</td></tr>
<tr><td>%reload_ext</td><td> Reload an IPython extension by its module name.</td></tr>
<tr><td>%rep</td><td> Repeat a command, or get command to input line for editing.</td></tr>
<tr><td>%rerun</td><td> Re-run previous input</td></tr>
<tr><td>%reset</td><td> Resets the namespace by removing all names defined by the user, if</td></tr>
<tr><td>%reset_selective</td><td> Resets the namespace by removing names defined by the user.</td></tr>
<tr><td>%run</td><td> Run the named file inside IPython as a program.</td></tr>
<tr><td>%save</td><td> Save a set of lines or a macro to a given filename.</td></tr>
<tr><td>%sc</td><td> Shell capture - run shell command and capture output (DEPRECATED use !).</td></tr>
<tr><td>%store</td><td> Lightweight persistence for python variables.</td></tr>
<tr><td>%sx</td><td> Shell execute - run shell command and capture output (!! is short-hand).</td></tr>
<tr><td>%system</td><td> Shell execute - run shell command and capture output (!! is short-hand).</td></tr>
<tr><td>%tb</td><td> Print the last traceback with the currently active exception mode.</td></tr>
<tr><td>%time</td><td> Time execution of a Python statement or expression.</td></tr>
<tr><td>%timeit</td><td> Time execution of a Python statement or expression</td></tr>
<tr><td>%unalias</td><td> Remove an alias</td></tr>
<tr><td>%unload_ext</td><td> Unload an IPython extension by its module name.</td></tr>
<tr><td>%who</td><td> Print all interactive variables, with some minimal formatting.</td></tr>
<tr><td>%who_ls</td><td> Return a sorted list of all interactive variables.</td></tr>
<tr><td>%whos</td><td> Like %who, but gives some extra information about each variable.</td></tr>
<tr><td>%xdel</td><td> Delete a variable, trying to clear it from anywhere that</td></tr>
<tr><td>%xmode</td><td> Switch modes for the exception handlers.</td></tr>
<tr><td>%%!</td><td> Shell execute - run shell command and capture output (!! is short-hand).</td></tr>
<tr><td>%%bash</td><td> %%bash script magic</td></tr>
<tr><td>%%capture</td><td> %capture [--no-stderr] [--no-stdout] [output]</td></tr>
<tr><td>%%file</td><td> %file [-a] filename</td></tr>
<tr><td>%%perl</td><td> %%perl script magic</td></tr>
<tr><td>%%prun</td><td> Run a statement through the python code profiler.</td></tr>
<tr><td>%%python3</td><td> %%python3 script magic</td></tr>
<tr><td>%%ruby</td><td> %%ruby script magic</td></tr>
<tr><td>%%script</td><td> %shebang [--proc PROC] [--bg] [--err ERR] [--out OUT]</td></tr>
<tr><td>%%sh</td><td> %%sh script magic</td></tr>
<tr><td>%%sx</td><td> Shell execute - run shell command and capture output (!! is short-hand).</td></tr>
<tr><td>%%system</td><td> Shell execute - run shell command and capture output (!! is short-hand).</td></tr>
<tr><td>%%timeit</td><td> Time execution of a Python statement or expression</td></tr>
</table>
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment