在 Python 代码中放置 PDB 断点的更简单方法? [英] Simpler way to put PDB breakpoints in Python code?
问题描述
只是一个方便的问题.我对 Visual Studio 和 XCode 等 IDE 中的调试器有些厌烦.我觉得必须输入 import pdb; 有点笨拙;pdb.set_trace()
设置断点(我不想在文件顶部导入 pdb,因为我可能会忘记并保留它).
Just a convenience question. I've been a bit spoiled with debuggers in IDEs like Visual Studio and XCode. I find it a bit clumsy to have to type import pdb; pdb.set_trace()
to set a breakpoint (I'd rather not import pdb at the top of the file as I might forget and leave it in).
是否有一种更简单的方法可以在 Python 代码中设置断点,就像您在 IDE 中看到的那样简单明了?
Is there a simpler way of setting a breakpoint in Python code, as straightforward and unobtrusive as what you see in an IDE?
推荐答案
您可以通过运行
python -m pdb your_script.py
python -m pdb your_script.py
它将在第一行中断,然后您可以使用 break
命令在代码中的任何位置添加断点,其语法为:
It will break on the 1st line, then you'll be able to add a breakpoint wherever you want in your code using the break
command, its syntax is:
b(reak) [[文件名:]lineno |函数[,条件]]
b(reak) [[filename:]lineno | function[, condition]]
它足够灵活,让您能够在任何地方添加断点.
It is flexible enough to give you the ability to add a breakpoint anywhere.
这篇关于在 Python 代码中放置 PDB 断点的更简单方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!