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 de
(self, parameter_s='')
| 87 | @skip_doctest |
| 88 | @line_magic |
| 89 | def cpaste(self, parameter_s=''): |
| 90 | """Paste & execute a pre-formatted code block from clipboard. |
| 91 | |
| 92 | You must terminate the block with '--' (two minus-signs) or Ctrl-D |
| 93 | alone on the line. You can also provide your own sentinel with '%paste |
| 94 | -s %%' ('%%' is the new sentinel for this operation). |
| 95 | |
| 96 | The block is dedented prior to execution to enable execution of method |
| 97 | definitions. '>' and '+' characters at the beginning of a line are |
| 98 | ignored, to allow pasting directly from e-mails, diff files and |
| 99 | doctests (the '...' continuation prompt is also stripped). The |
| 100 | executed block is also assigned to variable named 'pasted_block' for |
| 101 | later editing with '%edit pasted_block'. |
| 102 | |
| 103 | You can also pass a variable name as an argument, e.g. '%cpaste foo'. |
| 104 | This assigns the pasted block to variable 'foo' as string, without |
| 105 | dedenting or executing it (preceding >>> and + is still stripped) |
| 106 | |
| 107 | '%cpaste -r' re-executes the block previously entered by cpaste. |
| 108 | '%cpaste -q' suppresses any additional output messages. |
| 109 | |
| 110 | Do not be alarmed by garbled output on Windows (it's a readline bug). |
| 111 | Just press enter and type -- (and press enter again) and the block |
| 112 | will be what was just pasted. |
| 113 | |
| 114 | Shell escapes are not supported (yet). |
| 115 | |
| 116 | See Also |
| 117 | -------- |
| 118 | paste : automatically pull code from clipboard. |
| 119 | |
| 120 | Examples |
| 121 | -------- |
| 122 | :: |
| 123 | |
| 124 | In [8]: %cpaste |
| 125 | Pasting code; enter '--' alone on the line to stop. |
| 126 | :>>> a = ["world!", "Hello"] |
| 127 | :>>> print(" ".join(sorted(a))) |
| 128 | :-- |
| 129 | Hello world! |
| 130 | |
| 131 | :: |
| 132 | In [8]: %cpaste |
| 133 | Pasting code; enter '--' alone on the line to stop. |
| 134 | :>>> %alias_magic t timeit |
| 135 | :>>> %t -n1 pass |
| 136 | :-- |
| 137 | Created `%t` as an alias for `%timeit`. |
| 138 | Created `%%t` as an alias for `%%timeit`. |
| 139 | 354 ns ± 224 ns per loop (mean ± std. dev. of 7 runs, 1 loop each) |
| 140 | """ |
| 141 | opts, name = self.parse_options(parameter_s, 'rqs:', mode='string') |
| 142 | if 'r' in opts: |
| 143 | self.rerun_pasted() |
| 144 | return |
| 145 | |
| 146 | quiet = ('q' in opts) |
nothing calls this directly
no test coverage detected