Search
IPython Magics
from IPython.core.magic import register_line_magic, register_cell_magic

@register_line_magic
def lmagic(line):
    "my line magic"
    return line

@register_cell_magic
def cmagic(line, cell):
    "my cell magic"
    return line, cell

# We delete to avoid name conflicts for automagic to work
del lmagic
# Before
%lmagic Not valid python # this
# after
'Not valid python # this'
%%cmagic The part on the same line
The line after
The other line
('The part on the same line', 'The line after\nThe other line')