哪个 Python IDE 可以逐行运行我的脚本?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3999829/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 13:46:53  来源:igfitidea点击:

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

pythonide

提问by radek

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

我不会称自己为程序员,但我最近开始学习 Python 并且非常喜欢它。

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

到目前为止,我主要将它用于小任务 - 脚本编写、文本处理、KML 生成和 ArcGIS。

From my experience with R (working with excellent Notepad++ and NppToRcombo) 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.

根据我使用 R 的经验(使用出色的 Notepad++ 和NppToR组合),我通常尝试逐行(或逐个区域)使用我的脚本,以了解我的脚本的每个步骤在做什么......并检查结果苍蝇。

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

我的问题:是否有适用于 Windows 的 IDE(或编辑器?)可以让您评估单行 Python 脚本?

I haveseenquitea lot of discussion regarding IDEs in Python context.. but havent stubled upon this specific question so far.

已经看到相当大量的关于在Python方面的IDE讨论..但还没有在这个具体问题stubled至今。

Thanks for help!

感谢帮助!

采纳答案by Hao

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

即将推出的 RStudio 1.2 非常好,您必须尝试用它编写一些 Python。

回答by nmichaels

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.

它不是 IDE,但您可以使用 pdb 来调试和单步调试 Python 代码。我知道 Emacs 已经内置了对它的支持,但对将在 Windows 中运行的其他编辑器(或 IDE)的支持并不多。

回答by Chris

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

我唯一成功的是Eclipsewith Pydev

回答by duffymo

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

JetBrains 的PyCharm有一个非常好的调试器,您可以使用它来单步调试代码。

Django and console integration built in.

内置 Django 和控制台集成。

回答by David V

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

WingIDE,我已经成功使用它一年多了,对它非常满意。

回答by Sean Vieira

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

如果您使用的是 Windows,尝试一下Pyscripter—— 它提供全面的逐步调试,让您可以在代码的每一步检查变量的状态。

回答by bgporter

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

Pythonwin IDE 有一个内置调试器,可让您单步调试代码、检查变量等。

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

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

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

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

该包还包括一堆其他实用程序类和模块,它们在为 Windows 编写 Python 代码(与 COM 接口等)时非常有用。

It's also discussed in the O'Reilly book Python Programming On Win32by Mark Hammond.

Mark Hammond在 O'Reilly 的《Python Programming On Win32》一书中也讨论了这一点。

回答by S.Lott

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

提示一下:基本的 Python Read-Execute-Print-Loop (REPL) 必须工作。

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.

它是这样的:IDE 没有提供太多的替代方案。如果 REPL 无效,还有很多非常酷的替代方案。由于 REPL 非常有效,因此几乎没有其他选择。

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

请注意,像 Java 这样的语言必须有一个循序渐进的调试器,因为没有 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.

如果你的代码设计得很好,你可以导入你的函数和类库并在 REPL 模型中练习它们。通过在 REPL 级别运行包并复制交互来记录许多 Python 包。

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

Django 文档——作为一个例子——有很多交互式会话,演示了这些部分如何在 REPL 提示符下协同工作。

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

这不是很 GUI。几乎没有指向和点击。但它似乎是有效的。

回答by l337x911

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.

如果你喜欢 R 的布局。我强烈建议您试用Spyder。如果您使用的是 Windows,请尝试使用 Python(x,y)。它是一个包含几个不同编辑器和许多常见的额外模块(如 scipy 和 numpy)的包。

回答by Josh

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:

我使用 Notepad++ 进行大多数基于 Windows 的 Python 开发,并使用Winpdb进行调试。它是一个基于 GUI 的跨平台调试器。您实际上可以在 Notepad++ 中设置键盘快捷键以在当前脚本上启动调试器:

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

为此,请转到菜单中的“运行”->“运行...”并输入以下内容,确保路径指向您的 winpdb_.pyw 文件:

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:

PS:你也可以设置一个快捷方式来类似地使用这个字符串来执行你的python脚本:

C:\python26\python.exe "$(FULL_CURRENT_PATH)"

回答by dardisco

I would plump for EMACS all round.

我会全面支持 EMACS。

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

如果您正在寻找一个函数来逐行运行代码(或者一个区域,如果您有一个突出显示),请尝试将其添加到您的 .emacs(我正在使用 python.el 和 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 .Rfiles line by line here. I find both handy.

我已将其绑定到[shift-Return]. 这是从这里借来的。有一个类似的按键绑定运行.R一行一行的文件在这里。我觉得两者都很方便。