views:

258

answers:

5

Hi all,

When I am working with a Python Interpreter, I always find it a pain to try and copy code from it because it inserts all of these >>> and ...

Is there a Python interpreter that will let me copy code, without having to deal with this? Or alternatively, is there a way to clean the output.

Additionally, sometimes I would like to paste code in, but the code is indented. Is there any console that can automatically indent it instead of throwing an error?

Related

A: 

Decent text editors such as Notepad++ can make global search and replace operations that can replace >>> with nothing.

thereisnospork
By "decent" you mean *any* editor which is not only a Memo in a window? Because this is the basic of the basic... lol
Havenard
@Havenard, LOL
Cleiton
@thereisnospork: Oh, you mean something like `g/^>>> /s///` perhaps ... I had that in an editor on a CP/M box way back when (ported the Software Tools `edit` from Ratfor to C for light entertainment). That was decent compared to the supplied editor.
John Machin
+2  A: 

WingIDE from Wingware will let you evaluate any chunk of code in a separate interpreter window.

scrible
+1  A: 

IPython will let you paste Python code with leading indents without giving you an IndentationError. You can also change your prompts to remove >>> and ... if you wish.

Nicholas Riley
It definitely makes it easier, but unfortunately, I still get an extra line after my answer: iex=10a=11a+x21
Casebash
Sorry, comment doesn't display properly :-(
Casebash
Use the -nosep option to IPython (or the ipythonrc equivalents) to remove the blank lines.
Nicholas Riley
%history, %doctest_mode, %cpaste IPython's magic functions might help also.
J.F. Sebastian
%edit is useful for resolving issues with line breaks
Casebash
Ipython doesn't work with 3.0 :-(
Casebash
+1  A: 

I have a vim macro to "paste while cleaning interpreter prompts and sample output [[==stuff NOT preceded by prompts" and I'll be happy to share it if vim is what you're using. Any editor or IDE worth that name will of course be similarly easy to program for such purposes!

Alex Martelli
Thanks, I would like have that. I have used VIM, but I have never used macros. It probably isn't that hard to figure out.
Casebash
+4  A: 

IPython lets you show, save and edit your command history, for example to show the first three commands of your session without line numbers you'd type %hist -n 1 4.

Ants Aasma
`%hist` is an alternate name for `%history`
J.F. Sebastian
I had no idea about the -n option! Thanks!
Kenneth Reitz