2

I often use ipython (or the regular python shell) to test python code snippets while coding, and it's been very useful. One shortcoming of this, though, is that if I want to test a multi-line segment of code, or want to write multiple lines of code before running, it isn't very convenient to have to do it "line by line". And even going back to change some of the lines is cumbersome because you have to re-type all the code that comes after it.

I'm playing with Groovy right now and I find that it has an excellent solution to this problem: the Groovy Console. You just write all the code you want, it's just like a regular editor; and then you hit run Ctrl+R (Cmd+R actually since I'm on a Mac) and it runs everything at once. If you want to change something (e.g. if there are errors), then that's easy too -- just change it and Ctrl+R again.

Is there an equivalent of this available for python? Or do you have any recommendations on a way to achieve similar behavior? I could just create a new file, save it, and then python <filename>.py from the shell. But that's just too many steps and would be cumbersome. Eclipse may be an option, but it's too heavyweight. I'm really looking for something lightweight that I can just spin up when I want to test something and then get rid of it just as quickly.

I'd be interested to hear any ideas/suggestions!

Thanks

mindthief
  • 12,755
  • 14
  • 57
  • 61

4 Answers4

4

You might give DreamPie a try. As far as I can tell from a quick read of the groovyConsole page you linked to, DreamPie features a similar input area/output area division (they call it "code box" and "history box"). The code you execute is by default cleared from the code box - which groovyConsole apparently doesn't do - but you can easily retrieve it (Ctrl+Up), or change a preference setting to "Leave code in the code box after execution".

Steven
  • 28,002
  • 5
  • 61
  • 51
  • I finally got around to trying this, and -- DreamPie is not only exactly what I was looking for when I asked the question, it even has features I was wishing for in GroovyConsole! It has the best features of GroovyConsole and iPython, which really is all one could need. Thanks, this is a great find! – mindthief Mar 16 '11 at 20:56
3

Have you tried using IDLE, the standard Python IDE? You'd have to save the code as <filename>.py within IDLE, but after that you can run it using F5.

The Python docs link to this intro to IDLE, which may be helpful even if it's a little outdated.

Velociraptors
  • 2,012
  • 16
  • 22
  • Thanks, just tried IDLE, and the requirement to save the file is really the fly in the pudding on this one. You also need to open a new window after the initial launch (initial launch shows only a shell). Just little things but they're enough to deter. It's close, though... I'll have to try it a few times to see. – mindthief Feb 09 '11 at 18:14
2

I am using emacs and its python-mode.
C-c C-c: evals the current buffer
but you can also eval region (ie selection), functions etc ...

You can even make python-mode use ipython (like I do).
See http://ipython.scipy.org/dist/ipython.el . It works nicely

log0
  • 10,489
  • 4
  • 28
  • 62
1

Did you try PyCrust? It has excellent multi-line editing, copy/paste support.

PyCrust can be found in wxPython Docs and Demos.

Imran
  • 87,203
  • 23
  • 98
  • 131