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

bundles / IPython 9.14.0.dev / IPython / terminal / magics / TerminalMagics / paste

function

IPython.terminal.magics:TerminalMagics.paste

source: /IPython/terminal/magics.py :152

Signature

def   paste ( self parameter_s = '' )

Summary

Paste & execute a pre-formatted code block from clipboard.

Extended Summary

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.

Aliases

  • IPython.terminal.interactiveshell.TerminalMagics.paste