[IPython-user] cannot paste indented code

Arnd Baecker arnd.baecker at web.de
Thu Jan 5 00:57:32 CST 2006


Moin,

On Wed, 4 Jan 2006, Fernando Perez wrote:

> frank h. wrote:
> > hello,
> > i am new to ipython (using it on mac os x)
> >
> > I cannot seem to be able to paste indented code
> > below is the transcript of a session where I am trying to paste a
> > print statement into ipython that has a tab in front of it.
> > the same problem occurs when the print statement is preceeded with
> > spaces. it also occurs independent of the editor i am using to copy
> > from
> >
> > the line I am pasting:
> >
> >     print "ho"
>
> Let me add something, I realized I was too quick in my original reply.
>
> You can NOT paste code which STARTS indented, neither in ipython nor in the
> normal python shell.
>
>  >>>     print 'hi'
>    File "<stdin>", line 1
>      print 'hi'
>      ^
> SyntaxError: invalid syntax
>
>
> This is simply invalid python syntax, period.  You can find out more about the
> language from the python tutorial.

Interestingly, I also thought that something like this would work
now. I quite often have a few lines of code in a program,
which I would like to test interactively
(eg also after an ipshell call ...). Usually that code segment
is indented. To paste that part, I copy/paste it into a scratch
buffer of xemacs, do a rectangle select (eg. via mouse) and
then C-x r k  for rectangle-kill. Then the result can be
pasted into ipython.
I am not sure if it is possible to strip all " " automatically
from an input line (and the same number from the following ones)
until a double line break is encountered?
(I know that with readline this presumably cannot be
displayed properly, but still).

Maybe I should change my workflow, but this is presumably
the no1 annoyance ... ;-)
(We better don't talk about how I feel if I have to use a normal
python prompt - no time for this as I have to wade through
another 40 mails wrt scipy_core - aeh numpy ;-)

> What ipython (as of 0.7.0) has is support for pasting tab-indented multiline
> input without getting confused.

And I thought TABs are evil ;-)

Best, Arnd




More information about the IPython-user mailing list