Skip to content
Browse files

Added Example on cpaste

Workdone by:
 -  Lakshmi Bhavani.B
 -  Sathesh Chandra.B
 -  Karthik.P
 -  Ravi Chandra.B
  • Loading branch information...
1 parent 3498382 commit 46ff88c05b4eb583921301ae885caa96a7bec5c5 @sathya5562 committed
Showing with 21 additions and 39 deletions.
  1. +21 −39 IPython/frontend/terminal/interactiveshell.py
View
60 IPython/frontend/terminal/interactiveshell.py
@@ -545,51 +545,33 @@ def magic_cpaste(self, parameter_s=''):
See also
--------
paste: automatically pull code from clipboard.
- """
-
- opts,args = self.parse_options(parameter_s,'rs:',mode='string')
- par = args.strip()
- if opts.has_key('r'):
- self._rerun_pasted()
- return
-
- sentinel = opts.get('s','--')
-
- block = self._strip_pasted_lines_for_code(
- self._get_pasted_lines(sentinel))
-
- self._execute_block(block, par)
+
+ Example
+ -------
+ This is an example of creating a simple function to create the code
+ and then paste
+ Intially type the command %cpaste is Paste & execute a
+ pre-formatted code block from clipboard
+ You must terminate the block with '--' (two minus-signs) alone on the
+ line::
- def magic_paste(self, parameter_s=''):
- """Paste & execute a pre-formatted code block from clipboard.
+ In [9]: %cpaste
+ Pasting code; enter '--' alone on the line to stop.
+ :a = 5
+ :b = 6
+ :--
- 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).
+ Pasting.... done.Executing Pasted code
- 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
- dedenting or executing it (preceding >>> and + is still stripped)
+ In [10]: %cpaste -r
+ Re-executing 'a = 5...' (12 chars)
- Options
- -------
-
- -r: re-executes the block previously entered by cpaste.
+ In [11]: a
+ Out[11]: 5
- -q: quiet mode: do not echo the pasted text back to the terminal.
-
- IPython statements (magics, shell escapes) are not supported (yet).
+ In [12]: b
+ Out[12]: 6
- See also
- --------
- cpaste: manually paste code into terminal until you mark its end.
"""
opts,args = self.parse_options(parameter_s,'rq',mode='string')
par = args.strip()

0 comments on commit 46ff88c

Please sign in to comment.
Something went wrong with that request. Please try again.