在 emacs 中调试 python 程序

发布于 2024-08-22 22:48:07 字数 142 浏览 8 评论 0原文

如何在 emacs 中调试 python 程序?我正在使用 python-mode.el

我发现参考文献建议:

import pdb; pdb.set_trace();

但我不确定如何使用它。

How do I debug python programs in emacs? I'm using python-mode.el

I've found references suggesting:

import pdb; pdb.set_trace();

but I'm not sure how to use it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

姜生凉生 2024-08-29 22:48:08

realgud 包(可从 MELPA 获得)支持 PDB(以及无数其他调试器),并且具有许多 Emac 的 PDB 所没有的简洁功能。

我最喜欢的是快捷键模式。一旦开始调试程序,您可以直接在源代码窗口中按 nsc 等,而不必键入这些PDB 缓冲区中的命令。它还支持带有功能键的 Visual-Studio 样式键绑定(f10f11f5 等)。

安装RealGUD后,需要运行Mx load-feature realgud来加载它,并且可以使用Mx realgud:pdb启动pdb

The realgud package (available from MELPA) supports PDB (among a gazillion other debuggers), and has a host of neat features that Emac's PDB doesn't have.

The one I like best is the shortkeys mode. Once you start debugging a program, you can press n, s, c etc. right in the source window, instead of having to type these commands in the PDB buffer. It also supports Visual-Studio style keybindings with function keys (f10, f11, f5, etc).

After installing RealGUD, you need to run M-x load-feature realgud to load it, and you can start pdb with M-x realgud:pdb.

甜味超标? 2024-08-29 22:48:07

输入 Mx cd 将目录更改为您要调试的程序的位置。
输入Mx pdb。系统将提示您运行 pdb(如下所示):pdb。输入程序的名称(例如test.py)。

(Pdb) 提示符下,键入 help 以了解如何使用 pdb。

或者,您可以

import pdb 
pdb.set_trace()

直接放在程序中(例如 test.py)。现在输入 Mx shell 以获取 shell 提示符。当您运行程序时,您将在执行 pdb.set_trace() 时转储到 pdb 中。

Type M-x cd to change directory to the location of the program you wish to debug.
Type M-x pdb. You'll be prompted with Run pdb (like this): pdb. Enter the name of the program (e.g. test.py).

At the (Pdb) prompt, type help to learn about how to use pdb.

Alternatively, you can put

import pdb 
pdb.set_trace()

right inside your program (e.g. test.py). Now type M-x shell to get a shell prompt. When you run your program, you'll be dumped into pdb at the point where pdb.set_trace() is executed.

我最亲爱的 2024-08-29 22:48:07

对我来说,我需要将默认的“pdb”替换为

python -m pdb myscript.py

For me, I needed to replace the default "pdb" with

python -m pdb myscript.py
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文