IPython or Jupyter Notebook Magics

#Python #Jupyter #Bash

IPython or Jupyter Notebook Magics

Summary of the video lectures on IPython:

  • % is line level magic, which only affects the code starting from the position of it, while %% is cell level magic;
  • List all the magics: %lsmagic;
  • Timing of a cell: %timeit , for example, %timeit np.cos(1.3);
  • Write the content of the cell to a file by using %%writefile output.py;
  • Bash commands can be used in the command mod, by simply using a !, for example, !ls -l (Tab to autocomplete);
  • %run output.py can run the file;
  • Run a background job using %%python --bg --out output.txt then followed by the python code;
  • Plots inline can be made using %matplotlib inline;

Published: by ;

Lei Ma (2015). 'IPython or Jupyter Notebook Magics', Datumorphism, 12 April. Available at: https://datumorphism.leima.is/til/programming/ipython-or-jupyter-notebook-magics/.

Table of Contents

Current Ref:

  • til/programming/ipython-or-jupyter-notebook-magics.md