This is a development version (latest) and may be unstable. Go to latest (9.13.0)
{ } Raw JSON

bundles / IPython latest / IPython / core / magics / execution / ExecutionMagics / code_wrap

function

IPython.core.magics.execution:ExecutionMagics.code_wrap

source: /IPython/core/magics/execution.py :1586

Signature

def   code_wrap ( self line cell = None )

Summary

::

Extended Summary

%code_wrap [--remove] [--list] [--list-all] [name]

Simple magic to quickly define a code transformer for all IPython's future input.

__code__ and __ret__ are special variable that represent the code to run and the value of the last expression of __code__ respectively.

Examples

.. ipython:: In [1]: %%code_wrap before_after ...: print('before') ...: __code__ ...: print('after') ...: __ret__ In [2]: 1 before after Out[2]: 1 In [3]: %code_wrap --list before_after In [4]: %code_wrap --list-all before_after : print('before') __code__ print('after') __ret__ In [5]: %code_wrap --remove before_after positional arguments: name options: --remove remove the current transformer --list list existing transformers name --list-all list existing transformers name and code template

Aliases

  • IPython.core.magics.ExecutionMagics.code_wrap