Python -Vs- Ruby: A regexp match to the death!

Stefan Schwarzer sschwarzer at sschwarzer.net
Mon Aug 9 13:42:12 CEST 2010


Hi Steven,

On 2010-08-09 10:21, Steven D'Aprano wrote:
> And that it's quite finicky about blank lines between methods and inside 
> functions. Makes it hard to paste code directly into the interpreter.
> 
> And that pasting doesn't strip out any leading prompts. It needs a good 
> doctest mode.

ipython [1] should help here:

  IPython 0.10 -- An enhanced Interactive Python.
  ?         -> Introduction and overview of IPython's features.
  %quickref -> Quick reference.
  help      -> Python's own help system.
  object?   -> Details about 'object'. ?object also works, ?? prints more.
  In [1]: %paste?
  Type:           Magic function
  Base Class:     <type 'instancemethod'>
  String Form:    <bound method InteractiveShell.magic_paste of <IPython.iplib.InteractiveShell object at 0xb740096c>>
  Namespace:      IPython internal
  File:           /usr/lib/pymodules/python2.6/IPython/Magic.py
  Definition:     %paste(self, parameter_s='')
  Docstring:
      Allows you to paste & execute a pre-formatted code block from clipboard.

      The text is pulled directly from the clipboard without user
      intervention.

      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)

      '%paste -r' re-executes the block previously entered by cpaste.

      IPython statements (magics, shell escapes) are not supported (yet).

      See also
      --------
      cpaste: manually paste code into terminal until you mark its end.

Unfortunatey, when I enter

  In [2]: %paste

at the prompt it gives me (before I pasted anything)

  In [2]: %paste
  ------------------------------------------------------------
     File "<string>", line 1
       http://pypi.python.org/pypi/ipython/0.10
           ^
  SyntaxError: invalid syntax

So far, I couldn't find anything on the net on this.

[1] http://pypi.python.org/pypi/ipython

Stefan



More information about the Python-list mailing list