MCPcopy Index your code
hub / github.com/ipython/ipython / magic

Method magic

IPython/core/magics/basic.py:209–280  ·  view source on GitHub ↗

Print information about the magic function system. Supported formats: -latex, -brief, -rest

(self, parameter_s='')

Source from the content-addressed store, hash-verified

207
208 @line_magic
209 def magic(self, parameter_s=''):
210 """Print information about the magic function system.
211
212 Supported formats: -latex, -brief, -rest
213 """
214
215 mode = ''
216 try:
217 mode = parameter_s.split()[0][1:]
218 except IndexError:
219 pass
220
221 brief = (mode == 'brief')
222 rest = (mode == 'rest')
223 magic_docs = self._magic_docs(brief, rest)
224
225 if mode == 'latex':
226 print(self.format_latex(magic_docs))
227 return
228 else:
229 magic_docs = format_screen(magic_docs)
230
231 out = ["""
232IPython's 'magic' functions
233===========================
234
235The magic function system provides a series of functions which allow you to
236control the behavior of IPython itself, plus a lot of system-type
237features. There are two kinds of magics, line-oriented and cell-oriented.
238
239Line magics are prefixed with the % character and work much like OS
240command-line calls: they get as an argument the rest of the line, where
241arguments are passed without parentheses or quotes. For example, this will
242time the given statement::
243
244 %timeit range(1000)
245
246Cell magics are prefixed with a double %%, and they are functions that get as
247an argument not only the rest of the line, but also the lines below it in a
248separate argument. These magics are called with two arguments: the rest of the
249call line and the body of the cell, consisting of the lines below the first.
250For example::
251
252 %%timeit x = numpy.random.randn((100, 100))
253 numpy.linalg.svd(x)
254
255will time the execution of the numpy svd routine, running the assignment of x
256as part of the setup phase, which is not timed.
257
258In a line-oriented client (the terminal or Qt console IPython), starting a new
259input with %% will automatically enter cell mode, and IPython will continue
260reading input until a blank line is given. In the notebook, simply type the
261whole cell as one entity, but keep in mind that the %% escape can only be at
262the very start of the cell.
263
264NOTE: If you have 'automagic' enabled (via the command line option or with the
265%automagic function), you don't need to type in the % explicitly for line
266magics; cell magics always require an explicit '%%' escape. By default,

Callers

nothing calls this directly

Calls 5

_magic_docsMethod · 0.95
lsmagicMethod · 0.95
format_screenFunction · 0.90
format_latexMethod · 0.80
pageMethod · 0.80

Tested by

no test coverage detected