import_pdb

Posted on Mar 30, 2019

pdb – the python debugger

最近在python学习中用到了pdb调试模块(在没有IDE的情况下debug应该特别好用),做一点笔记:

首先, import pdb, 在需要调试的地方设置断点 pdb.set_trace(), 执行程序进入断点。

常用命令

命令功能
next(n)执行下一行
exit(q)中止调试并退出
continue(c)停止debug继续执行程序
where(w)找出当前代码的运行位置
list(l)显示当前行的代码段
print(p)打印变量的值
step(s)进入函数
return(r)执行代码直到当前函数返回(return)
help帮助

参考 python pdb模块 官方文档 版本:3.7

The module pdb defines an interactive source code debugger for Python programs. It supports setting (conditional) breakpoints and single stepping at the source line level, inspection of stack frames, source code listing, and evaluation of arbitrary Python code in the context of any stack frame. It also supports post-mortem debugging and can be called under program control.