MCPcopy Create free account
hub / github.com/ipython/ipython / magic

Method magic

IPython/core/magics/basic.py:204–275  ·  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

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

Callers 15

test_historyFunction · 0.45
check_cpasteFunction · 0.45
pasteMethod · 0.45
test_paste_py_multi_rMethod · 0.45
test_handlersFunction · 0.45
test_magic_not_foundFunction · 0.45
test_configFunction · 0.45
test_config_print_classFunction · 0.45
test_rehashxFunction · 0.45
test_macroFunction · 0.45
test_magic_magicFunction · 0.45

Calls 5

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

Tested by 15

test_historyFunction · 0.36
check_cpasteFunction · 0.36
pasteMethod · 0.36
test_paste_py_multi_rMethod · 0.36
test_handlersFunction · 0.36
test_magic_not_foundFunction · 0.36
test_configFunction · 0.36
test_config_print_classFunction · 0.36
test_rehashxFunction · 0.36
test_macroFunction · 0.36
test_magic_magicFunction · 0.36