[IPython-user] pasting code

Fernando Perez Fernando.Perez at colorado.edu
Sat Dec 31 14:39:13 CST 2005

Hi David,

[ in case you are not on the list anymore, this is CC-d directly]

Note that this was sent in August 2003!

David Grote wrote:
> Thanks for your quick response! I would suggest something like this...
> You already keep track of the indentation level (for autoindent). So, 
> whenever the indent level is 0, always strip off any leading spaces and 
> remember the number of spaces. Then, in higher indent levels, always 
> remove the number of spaces from the most recent level 0 line. Similar 
> to what you suggested but not quite the same.
>    Dave
> Fernando Perez wrote:
>>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,

Well, nobody is going to accuse me of being fast with development here, but 
0.7.0 finally has this request taken care of :)  Downloads here:




More information about the IPython-user mailing list