You are viewing an older version (9.5.0). Go to latest (9.13.0)
{ } Raw JSON

bundles / IPython 9.5.0 / IPython / core / magic / MagicsManager / register_function

function

IPython.core.magic:MagicsManager.register_function

source: /IPython/core/magic.py :464

Signature

def   register_function ( self func magic_kind = line magic_name = None )

Summary

Expose a standalone function as magic function for IPython.

Extended Summary

This will create an IPython magic (line, cell or both) from a standalone function. The functions should have the following signatures:

  • For line magics: def f(line)

  • For cell magics: def f(line, cell)

  • For a function that does both: def f(line, cell=None)

In the latter case, the function will be called with cell==None when invoked as %f, and with cell as a string when invoked as %%f.

Parameters

func : callable

Function to be registered as a magic.

magic_kind : str

Kind of magic, one of 'line', 'cell' or 'line_cell'

magic_name : optional str

If given, the name the magic will have in the IPython namespace. By default, the name of the function itself is used.

Aliases

  • IPython.InteractiveShell.register_magic_function
  • IPython.core.magic.MagicsManager.register_function

Referenced by