diff --git a/IPython/core/magics/basic.py b/IPython/core/magics/basic.py index 7f062c1..d170253 100644 --- a/IPython/core/magics/basic.py +++ b/IPython/core/magics/basic.py @@ -120,11 +120,36 @@ IPython's 'magic' functions The magic function system provides a series of functions which allow you to control the behavior of IPython itself, plus a lot of system-type -features. All these functions are prefixed with a % character, but parameters -are given without parentheses or quotes. +features. There are two kinds of magics, line-oriented and cell-oriented. + +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. For example, this will +time the given statement:: + + %timeit range(1000) + +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. These magics are called with two arguments: the rest of the +call line and the body of the cell, consisting of the lines below the first. +For example:: + + %%timeit x = numpy.random.randn((100, 100)) + numpy.linalg.svd(x) + +will time the execution of the numpy svd routine, running the assignment of x +as part of the setup phase, which is not timed. + +In a line-oriented client (the terminal or Qt console IPython), starting a new +input with %% will automatically enter cell mode, and IPython will continue +reading input until a blank line is given. In the notebook, simply type the +whole cell as one entity, but keep in mind that the %% escape can only be at +the very start of the cell. NOTE: If you have 'automagic' enabled (via the command line option or with the -%automagic function), you don't need to type in the % explicitly. By default, +%automagic function), you don't need to type in the % explicitly for line +magics; cell magics always require an explicit '%%' escape. By default, IPython ships with automagic on, so you should only rarely need the % escape. Example: typing '%cd mydir' (without the quotes) changes you working directory