Important
This documentation covers IPython versions 6.0 and higher. Beginning with version 6.0, IPython stopped supporting compatibility with Python versions lower than 3.3 including all versions of Python 2.7.
If you are looking for an IPython version compatible with Python 2.7, please use the IPython 5.x LTS release and refer to its documentation (LTS is the long term support release).
Module: terminal.magics
¶
Extra magics for terminal use.
1 Class¶
- class IPython.terminal.magics.TerminalMagics(**kwargs: Any)¶
Bases:
Magics
- __init__(shell)¶
Create a configurable given a config config.
- Parameters:
config (Config) – If this is empty, default values are used. If config is a
Config
instance, it will be used to configure the instance.parent (Configurable instance, optional) – The parent Configurable instance of this object.
Notes
Subclasses of Configurable must call the
__init__()
method ofConfigurable
before doing anything else and usingsuper()
:class MyConfigurable(Configurable): def __init__(self, config=None): super(MyConfigurable, self).__init__(config=config) # Then any other code you need to finish initialization.
This ensures that instances will be configured properly.
- autoindent(parameter_s='')¶
Toggle autoindent on/off (deprecated)
- cpaste(parameter_s='')¶
Paste & execute a pre-formatted code block from clipboard.
You must terminate the block with ‘–’ (two minus-signs) or Ctrl-D alone on the line. You can also provide your own sentinel with ‘%paste -s %%’ (‘%%’ is the new sentinel for this operation).
The block is dedented prior to execution to enable execution of method definitions. ‘>’ and ‘+’ characters at the beginning of a line are ignored, to allow pasting directly from e-mails, diff files and doctests (the ‘…’ continuation prompt is also stripped). The executed block is also assigned to variable named ‘pasted_block’ for later editing with ‘%edit pasted_block’.
You can also pass a variable name as an argument, e.g. ‘%cpaste foo’. This assigns the pasted block to variable ‘foo’ as string, without dedenting or executing it (preceding >>> and + is still stripped)
‘%cpaste -r’ re-executes the block previously entered by cpaste. ‘%cpaste -q’ suppresses any additional output messages.
Do not be alarmed by garbled output on Windows (it’s a readline bug). Just press enter and type – (and press enter again) and the block will be what was just pasted.
Shell escapes are not supported (yet).
See also
paste
automatically pull code from clipboard.
Examples
In [8]: %cpaste Pasting code; enter '--' alone on the line to stop. :>>> a = ["world!", "Hello"] :>>> print(" ".join(sorted(a))) :-- Hello world!
- ::
In [8]: %cpaste Pasting code; enter ‘–’ alone on the line to stop. :>>> %alias_magic t timeit :>>> %t -n1 pass :– Created
%t
as an alias for%timeit
. Created%%t
as an alias for%%timeit
. 354 ns ± 224 ns per loop (mean ± std. dev. of 7 runs, 1 loop each)
- paste(parameter_s='')¶
Paste & execute a pre-formatted code block from clipboard.
The text is pulled directly from the clipboard without user intervention and printed back on the screen before execution (unless the -q flag is given to force quiet mode).
The block is dedented prior to execution to enable execution of method definitions. ‘>’ and ‘+’ characters at the beginning of a line are ignored, to allow pasting directly from e-mails, diff files and doctests (the ‘…’ continuation prompt is also stripped). The executed block is also assigned to variable named ‘pasted_block’ for later editing with ‘%edit pasted_block’.
You can also pass a variable name as an argument, e.g. ‘%paste foo’. This assigns the pasted block to variable ‘foo’ as string, without executing it (preceding >>> and + is still stripped).
Options:
-r: re-executes the block previously entered by cpaste.
-q: quiet mode: do not echo the pasted text back to the terminal.
IPython statements (magics, shell escapes) are not supported (yet).
See also
cpaste
manually paste code into terminal until you mark its end.
- rerun_pasted(name='pasted_block')¶
Rerun a previously pasted command.
- store_or_execute(block, name, store_history=False)¶
Execute a block, or store it in a variable, per the user’s request.
1 Function¶
- IPython.terminal.magics.get_pasted_lines(sentinel, l_input=<function input>, quiet=False)¶
Yield pasted lines until the user enters the given sentinel value.