[IPython-user] cannot paste indented code
Fernando Perez
Fernando.Perez at colorado.edu
Thu Jan 5 01:16:21 CST 2006
Arnd Baecker wrote:
>>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).
I'll file this as a feature request, though I'm slightly apprehensive of
adding this much magic on top of the language. I feel like ipython is
becoming more and more a 'new thing' on top of python.
But yes, I also see the convenience value here... I'm not really sure whether
to go for it (there is a runtime price to pay for the extra analysis, as well
as more complexity in the input analyzer, so thid doesn't come for free).
Note that you can already do this:
In [36]: if 1:
....: print 'hi arnd'
....: for i in (1,2):
....: print i,
....: print 'bye'
....:
hi arnd
1 2 bye
Just add an 'if 1:' at the first line, and paste away, even if the code is
indented multiple levels (the above was a chunk twice-indented in an emacs
buffer).
>>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 ;-)
They are, but ipython isn't into fixing anyone's moral compass :)
Cheers,
f
More information about the IPython-user
mailing list