1

There is a lot of discussion of %load_ext magic in Python (e.g. here https://ipython.readthedocs.io/en/stable/config/extensions/index.html)

One thing that has always confused me though: what is the % doing / what does it mean?

Why isn't the relevant code just called by load_ext

  • 3
    Well if you enter something in a jupyter cell jupyter has to know you're talking about a jupyter command rather than Julia, Python or R code. You tell it with `%` or `%%`. E.g. If you want to make it run your a function multiple times and give you statistics on how long it took you could do `%timeit my_function()`. – Lukas S May 03 '22 at 21:31

1 Answers1

3

From the IPython docs, Built-in magic commands:

Note To Jupyter users: Magics are specific to and provided by the IPython kernel. Whether Magics are available on a kernel is a decision that is made by the kernel developer on a per-kernel basis. To work properly, Magics must use a syntax element which is not valid in the underlying language. For example, the IPython kernel uses the % syntax element for Magics as % is not a valid unary operator in Python. However, % might have meaning in other languages.

(By the way, %load_ext is covered in brief on the same page.)


Related questions:

wjandrea
  • 28,235
  • 9
  • 60
  • 81