Which Python IDE can run my script line-by-line?

Question:

I wouldn’t call myself programmer, but I’ve started learning Python recently and really enjoy it.

I mainly use it for small tasks so far – scripting, text processing, KML generation and ArcGIS.

From my experience with R (working with excellent Notepad++ and NppToR combo) I usually try to work with my scripts line by line (or region by region) in order to understand what each step of my script is doing.. and to check results on the fly.

My question: is there and IDE (or editor?) for Windows that lets you evaluate single line of Python script?

I have seen quite a lot of discussion regarding IDEs in Python context.. but havent stubled upon this specific question so far.

Thanks for help!

Asked By: radek

||

Answers:

It’s not an IDE, but you can use pdb to debug and step through your Python code. I know Emacs has built in support for it, but not so much about other editors (or IDEs) that will run in Windows.

Answered By: nmichaels

The only one I’ve had success with is Eclipse with Pydev

Answered By: Chris

PyCharm from JetBrains has a very nice debugger that you can step through code with.

Django and console integration built in.

Answered By: duffymo

WingIDE, I’ve been using it successfully for over a year, and very pleased with it.

Answered By: David V

If you are on Windows, give Pyscripter a try — it offers comprehensive, step-through debugging, which will let you examine the state of your variables at each step of your code.

Answered By: Sean Vieira

The Pythonwin IDE has a built-in debugger at lets you step through your code, inspect variables, etc.

http://starship.python.net/crew/mhammond/win32/Downloads.html

http://sourceforge.net/projects/pywin32/

The package also includes a bunch of other utility classes and modules that are very useful when writing Python code for Windows (interfacing with COM, etc.).

It’s also discussed in the O’Reilly book Python Programming On Win32 by Mark Hammond.

Answered By: bgporter

Take the hint: The basic Python Read-Execute-Print-Loop (REPL) must work.

Want Evidence?

Here it is: The IDE’s don’t offer much of an alternative. If REPL wasn’t effective, there’s be lots of very cool alternatives. Since REPL is so effective, there are few alternatives.

Note that languages like Java must have a step-by-step debugger because there’s no REPL.

Here’s the other hint.

If you design your code well, you can import your libraries of functions and classes and exercise them in REPL model. Many, many Python packages are documented by exercising the package at the REPL level and copying the interactions.

The Django documentation — as one example — has a lot of interactive sessions that demonstrate how the parts work together at the REPL prompt.

This isn’t very GUI. There’s little pointing and clicking. But it seems to be effective.

Answered By: S.Lott

If you like R’s layout. I highly recommend trying out Spyder. If you are using windows, try out Python(x,y). It is a package with a few different editors and a lot of common extra modules like scipy and numpy.

Answered By: l337x911

I use Notepad++ for most of my Windows based Python development and for debugging I use Winpdb. It’s a cross platform GUI based debugger. You can actually setup a keyboard shortcut in Notepad++ to launch the debugger on your current script:

To do this go to “Run” -> “Run …” in the menu and enter the following, making sure the path points to your winpdb_.pyw file:

C:python26Scriptswinpdb_.pyw "$(FULL_CURRENT_PATH)"

Then choose “Save…” and pick a shortcut that you wish to use to launch the debugger.

PS: You can also setup a shortcut to execute your python scripts similarly using this string instead:

C:python26python.exe "$(FULL_CURRENT_PATH)"
Answered By: Josh

I would plump for EMACS all round.

If you’re looking for a function to run code line by line (or a region if you have one highlighted), try adding this to your .emacs (I’m using python.el and Pymacs):

;; send current line to *Python
(defun my-python-send-region (&optional beg end)
(interactive)
(let ((beg (cond (beg beg)
               ((region-active-p)
                (region-beginning))
               (t (line-beginning-position))))
    (end (cond (end end)
               ((region-active-p)
                (copy-marker (region-end)))
               (t (line-end-position)))))
(python-shell-send-region beg end)))

(add-hook 'python-mode-hook
      '(lambda()
         (local-set-key [(shift return)] 'my-python-send-region)))

I’ve bound it to [shift-Return]. This is borrowed from here. There’s a similar keybinding for running .R files line by line here. I find both handy.

Answered By: dardisco

I like vim-ipython. With it I can <ctrl>+s to run a specific line. Or several lines selected on visual modes. Take a look at this video demo.

Answered By: Eder Santana

You need to set the keyboard shortcut for “run selection” in
Tools > Preferences > Keyboard shortcuts

Then, select the line and hit the “run selection” shortcut

Answered By: MasterJedi
Answered By: Aaron Hoffman

Rodeo seems to be new contender on the IDE market and the docs indicate that running lines of code is possible. I also have to admit it looks and behaves pretty good so far!

enter image description here

Answered By: radek

The upcoming RStudio 1.2 is so good that you have to try to write some python with it.

Answered By: Hao

Light Table was doing that for me, unfortunately it is discontinued:

INLINE EVALUTION No more printing to the console in order to view your
results. Simply evaluate your code and the results will be displayed
inline.

enter image description here

Answered By: Eduard Florinescu
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.