美文网首页
[module]pdb:python debugger 用法

[module]pdb:python debugger 用法

作者: 余名 | 来源:发表于2018-01-07 22:21 被阅读0次

从命令行运行

$ python -m pdb python_script.py
debugger会在脚本第一行指令处停止执行,进入pdb模式,可执行相应命令
命令列表:

  • c 继续执行
  • w 显示当前正在执行的代码行的上下文信息
  • a 打印当前函数的参数列表
  • s 执行当前代码行,并停在第一个能停的地方(相当于单步进入)
  • n 继续执行到当前函数的下一行,或者当前行直接返回(单步跳过)

从脚本内部运行

import pdb

def make_bread():
    pdb.set_trace()  # 运行脚本后会先停在这儿
    return "I don't have time"

print(make_bread())

相关文章

网友评论

      本文标题:[module]pdb:python debugger 用法

      本文链接:https://www.haomeiwen.com/subject/oqamnxtx.html