[IPython-user] pasting code
fperez at colorado.edu
Thu Aug 7 13:47:40 CDT 2003
David Grote wrote:
> One feature I've been looking for is a way to copy and paste code from a
> python file and have python ignore the leading spaces. For example, if I
> want to paste a few lines of code from inside of a function to the
> prompt, I get errors because of the indentation. I normally type "if 1:"
> before hand to get around the errors. I didn't a capability like this
> listed in the manual, so consider this a feature request to the developers.
Tricky to get right, but not impossible. It would have a cost, though: the
simplest solution seems to be to try the input, check for a SyntaxError, and
retry again with leading space removed. And for secondary lines and further,
one needs to remember how much space is being stripped, and strip only that much.
Getting the details right will take a bit of work. Right now I'm gearing up
to flush the large backlog of ipython work I have in preparation for scipy'03,
so this will fall to the bottom of a rather largish pile :) But I'll put it
in the todo list, so it may eventually get done. It would be implemented as
an option, though, so that during regular user you don't pay the extra cost.
Thanks for the input,
More information about the IPython-user