Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Doc magic cpaste #224

Closed
wants to merge 1 commit into from

2 participants

@sathya5562

Added examples for %cpaste and %paste as part of Scipy India sprint

@sathya5562 sathya5562 Added Example on cpaste
Workdone by:
 -  Lakshmi Bhavani.B
 -  Sathesh Chandra.B
 -  Karthik.P
 -  Ravi Chandra.B
46ff88c
@takluyver
Owner

Thanks sathya. Unfortunately it seems like you've accidentally removed the function while adding to the documentation (click on Diff above to see the changes).

@takluyver
Owner

The example for this was merged into pull request #272. Thanks again.

@damianavila damianavila referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 18, 2010
  1. @sathya5562

    Added Example on cpaste

    sathya5562 authored
    Workdone by:
     -  Lakshmi Bhavani.B
     -  Sathesh Chandra.B
     -  Karthik.P
     -  Ravi Chandra.B
This page is out of date. Refresh to see the latest.
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()
Something went wrong with that request. Please try again.