[IPython-user] pasting code

David Grote DPGrote at lbl.gov
Thu Aug 7 14:38:27 CDT 2003

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.

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,
> f.
> _______________________________________________
> IPython-user mailing list
> IPython-user at scipy.net
> http://scipy.net/mailman/listinfo/ipython-user

More information about the IPython-user mailing list