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

和自甴很熟 提交于 2019-12-20 09:28:42

问题


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!


回答1:


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




回答2:


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.




回答3:


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




回答4:


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.




回答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.




回答6:


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

Django and console integration built in.




回答7:


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




回答8:


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)"



回答9:


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.




回答10:


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!




回答11:


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.




回答12:


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

(There is also a REPL inside VS)




回答13:


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.




回答14:


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.




回答15:


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



来源:https://stackoverflow.com/questions/3999829/which-python-ide-can-run-my-script-line-by-line

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!