39

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!

Community
  • 1
  • 1
radek
  • 7,240
  • 8
  • 58
  • 83
  • 3
    It's called "Read-Execute-Print-Loop" REPL. THat's the way Python works. You type the line of code. It executes the line of code. If you weary of typing, copy and paste from a script work well, also. Since you already have this, what are you asking for? – S.Lott Oct 22 '10 at 18:41
  • 3
    I'm aware of that. Copy/pasting scripts that grow large can be rather tedious tho. – radek Oct 22 '10 at 18:52
  • Executing a "large" script one line at time can be rather tedious, though. – S.Lott Oct 22 '10 at 18:54
  • @S.Lott: sure thing - that's why I'm seraching for a solution to that. Some recent example looked more or less like that: fetch data from DB [takes a while on my slow machine and I need to do it just once], reorganize/aggregate/calculate data on the basis of query (here 'run lines' are really useful for me - i'm still learning.. and doing mistakes.. so want to be sure of results before next step), try different ways of representing data in KML (here 'run lines' is a bless). – radek Oct 22 '10 at 19:17

16 Answers16

16

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.

anatoly techtonik
  • 19,847
  • 9
  • 124
  • 140
l337x911
  • 171
  • 4
  • Bingo. From what I tried so far Spyder looks brilliant. Ctrl + F9 executes selection of the code. And Python(x,y) bundle comes with all other goodies to start learning about, including Eclipse, also recommended by others. Thanks! – radek Oct 24 '10 at 14:05
  • 1
    With Spyder 2.3.5.2 and Windows 7 the keyboard shorcut appears to be `F9`. – Niko Föhr Oct 07 '15 at 17:43
  • 3
    But how to run a current line and have the cursor moves to the next line like R? – Heisenberg Oct 25 '15 at 21:24
  • Indeed, on a mac the function key F9 (you may need to press `fn` + `F9`, depending on your keyboard setting). For _Spyder3_ on mac, if I use F9, the line where the cursor is will be run, and the cursor _will_ move onto the next line as in R. Uncertain whether the same is on Windows. – David C. Dec 17 '16 at 17:46
7

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

Chris
  • 3,438
  • 5
  • 25
  • 27
  • 2
    Eclipse with PyDev is a great choice. Stepping through code, in and out of function calls, around loops, etc is easily accomplished via break points when run in debug mode. It also includes code completion, import support, syntax analysis, and other great features. I used the combination on multiple Linux Distributions as well as Windows 32 and 64 bit without difficulty. – g.d.d.c Oct 22 '10 at 20:06
  • Thanks phasetwenty. PyDev seems to often come on top [http://stackoverflow.com/questions/81584/what-ide-to-use-for-python]. Might be time to give it a spin. – radek Oct 24 '10 at 14:00
5

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.

nmichaels
  • 49,466
  • 12
  • 107
  • 135
  • Thanks Nathon. I've heard lots of good comments about Emacs already. Especially that it offers very good support for R as well. Will have to try it I guess. – radek Oct 24 '10 at 14:01
5

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.

Sean Vieira
  • 155,703
  • 32
  • 311
  • 293
4

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

anatoly techtonik
  • 19,847
  • 9
  • 124
  • 140
radek
  • 7,240
  • 8
  • 58
  • 83
4

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

Django and console integration built in.

duffymo
  • 305,152
  • 44
  • 369
  • 561
  • 2
    Pycharm also has the "Execute selection in console", which runs the selection if anything is selected, and runs the current line if nothing is selected, just like Ctrl+r in Rstudio. I believe the default keymap is Alt+Shift+E, but this can be changed to e.g. Ctrl+r – Rasmus Larsen Jul 24 '14 at 07:38
3

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

David V
  • 31
  • 1
3

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:\python26\Scripts\winpdb_.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:\python26\python.exe "$(FULL_CURRENT_PATH)"
Josh
  • 2,158
  • 18
  • 22
  • Thanks offsound. Notepad++ is usually my first choice as well. Especially that you can nicely tie it to R and Stata, where I work most of the time. Basic Python editing is easy there as well. Haven't heard about Winpdb tho. Will have to check it. – radek Oct 24 '10 at 14:07
2

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.

dardisco
  • 5,086
  • 2
  • 39
  • 54
  • 1
    thanks for this, i also added a `(python-nav-forward-statement)` to the end of your let block to jump to the next line to run. – joefromct Oct 11 '16 at 18:05
2

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

Hao
  • 7,476
  • 1
  • 38
  • 59
1

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.

Eder Santana
  • 439
  • 1
  • 4
  • 8
1

Visual Studio and PTVS: http://www.hanselman.com/blog/OneOfMicrosoftsBestKeptSecretsPythonToolsForVisualStudioPTVS.aspx

(There is also a REPL inside VS)

Aaron Hoffman
  • 6,604
  • 8
  • 56
  • 61
0

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

MasterJedi
  • 1,618
  • 1
  • 18
  • 17
0

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.

bgporter
  • 35,114
  • 8
  • 59
  • 65
0

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.

S.Lott
  • 384,516
  • 81
  • 508
  • 779
0

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

Eduard Florinescu
  • 16,747
  • 28
  • 113
  • 179