Skip to content

+++ py.include_doctest = true +++

midgy and magicsยค

cell magics only built in to the language as they provide macro features for code.


magics can be in indented code

%%magic arguments
the body of the cell magic
is quoted and indents are maintained
get_ipython().run_cell_magic('magic', 'arguments',
"""the body of the cell magic
is quoted and indents are maintained""")

magics can be in code fences

```ipython
%%magic arguments 
the body 
```
# ```ipython
get_ipython().run_cell_magic('magic', 'arguments', 
"""the body""") 
# ```

magics can be in doctests

    >>> %%magic arguments 
    ... the body 
    some output
get_ipython().run_cell_magic('magic', 'arguments', 
"""the body""") 
# some output

magics can exist in the fence info

```%%magic arguments 
the body 
```
get_ipython().run_cell_magic('magic', 'arguments', # ``` 
"""the body""") 
# ```

this form is not friendly in native markdown mode