Lesson 7: Using Magic Commands

Magic Commands are powerful shortcuts exposed by the kernel that allow you to solve many common problems.

Read the magic documenation

  1. Input the command %magic to view the documentation for magic commands.

List all available magic commands

  1. Input the command %lsmagic to view all available magic commands.
  2. Press shift + enter

Run External Code using the %run magic command

  1. Create a python file outside of the Jupyter Notebook.
  2. To run an external file input the command %run <python file name>
  3. Press shift + enter
External python file
Run an External python file

Measure the execution time of code using %timeit magic command

  1. To measure a single line of code use %timeit magic command before the line of code you want to measure.
  2. To measure multiple lines of code use the %%timeit magic command before the lines of code you want to measure.
%timeit magic command

To use the shell use the %system magic command

  1. Use the %system magic command to use shell

Back to Menu