Python -Vs- Ruby: A regexp match to the death!
robert.kern at gmail.com
Mon Aug 9 22:23:11 CEST 2010
On 2010-08-09 06:42 , Stefan Schwarzer wrote:
> 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  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 : %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='')
> Allows you to paste& execute a pre-formatted code block from clipboard.
> The text is pulled directly from the clipboard without user
> 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 : %paste
> at the prompt it gives me (before I pasted anything)
> In : %paste
> File "<string>", line 1
> SyntaxError: invalid syntax
Yes, that's because you had that URL in your clipboard, not Python code. What
were you expecting to happen?
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
More information about the Python-list