iPython - Magic Function

Card Puncher Data Processing

About

iPython magic function can be called with a command line style syntax.

Type

There are two kinds of magics:

Line

Line magics are prefixed with the % character and work much like OS command-line calls: they get as an argument the rest of the line, where arguments are passed without parentheses or quotes. Lines magics can return results and can be used in the right hand side of an assignment.

Cell

Cell magics are prefixed with a double %%, and they are functions that get as an argument not only the rest of the line, but also the lines below it in a separate argument.

Management

help

  • on magic
%magic
  • one one magic function
%somemagic?

Capture output

myfiles = %sx ls

More Manual capture of command output and magic output

list

%lsmagic
Available line magics:
%alias  %alias_magic  %autocall  %autoindent  %automagic  %bookmark  %cd  %cls  %colors  %config  %copy  %cpaste  %ddir  %debug  %dhist  %dirs  %doctest_mode  %echo  %ed  %edit  %env  %gui  %hist  %history  %killbgscripts  %ldir  %load  %load_ext  %loadpy  %logoff  %logon  %logstart  %logstate  %logstop  %ls  %lsmagic  %macro  %magic  %matplotlib  %mkdir  %notebook  %page  %paste  %pastebin  %pdb  %pdef  %pdoc  %pfile  %pinfo  %pinfo2  %popd  %pprint  %precision  %profile  %prun  %psearch  %psource  %pushd  %pwd  %pycat  %pylab  %quickref  %recall  %rehashx  %reload_ext  %ren  %rep  %rerun  %reset  %reset_selective  %rmdir  %run  %save  %sc  %set_env  %store  %sx  %system  %tb  %time  %timeit  %unalias  %unload_ext  %who  %who_ls  %whos  %xdel  %xmode

Available cell magics:
%%!  %%HTML  %%SVG  %%bash  %%capture  %%cmd  %%debug  %%file  %%html  %%javascript  %%js  %%latex  %%markdown  %%perl  %%prun  %%pypy  %%python  %%python2  %%python3  %%ruby  %%script  %%sh  %%svg  %%sx  %%system  %%time  %%timeit  %%writefile

Automagic is ON, % prefix IS NOT needed for line magics.

Built-in

Example

http://nbviewer.ipython.org/urls/raw.github.com/ipython/ipython/1.x/examples/notebooks/Cell%20Magics.ipynb

Documentation / Reference





Discover More
Card Puncher Data Processing
IPython - Command

IPython - Command
Card Puncher Data Processing
IPython - Command History

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 Input and output history...
Sparkmagic Hello
Jupyter - SparkMagic

Sparkmagic is a kernel that provides Ipython magic for working with Spark clusters through Livy in Jupyter notebooks. installation ...
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...
Card Puncher Data Processing
iPython - File System

pushd popd dhist...



Share this page:
Follow us:
Task Runner