7

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

5 Answers 5

4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

%hist is an alternate name for %history
3

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

Comments

1

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.

4 Comments

It definitely makes it easier, but unfortunately, I still get an extra line after my answer: ie x=10 a=11 a+x 21
Sorry, comment doesn't display properly :-(
Use the -nosep option to IPython (or the ipythonrc equivalents) to remove the blank lines.
%history, %doctest_mode, %cpaste IPython's magic functions might help also.
1

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!

1 Comment

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.
0

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

2 Comments

By "decent" you mean any editor which is not only a Memo in a window? Because this is the basic of the basic... lol
@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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.