转载-python pdb调试以及sublime3快捷键设置

来源:互联网 发布:万网域名怎么解析 编辑:程序博客网 时间:2024/06/06 03:08

出处:https://www.cnblogs.com/xianwang/p/4916045.html
pdb调试

如果对gdb比较熟悉的话,pdb就很容易上手。以一个demo快速了解常用的调试命令。

def test(a):    while True:        if a > 10:            break        a += 1    return aif __name__ == '__main__':    test(1)
python -m pdb test.py进入调试环境b test在test函数处设置断点,断点号为1(Pdb) b testBreakpoint 1 at f:\python\pdb\test.py:1b 2在第二行设置断点,断点号为2(Pdb) b 2Breakpoint 2 at f:\python\pdb\test.py:2condition 2 a==7在2号断点处设置条件 a==7b显示所有断点信息(Pdb) bNum Type         Disp Enb   Where1   breakpoint   keep yes   at f:\python\pdb\test.py:12   breakpoint   keep yes   at f:\python\pdb\test.py:2stop only if a==7cl 1去除1号断点,只有cl删除所有断点(Pdb) cl 1Deleted breakpoint 1n单步跟踪,不进入函数(Pdb) n > f:\python\pdb\test.py(8)<module>()-> if __name__ == '__main__':(Pdb) n > f:\python\pdb\test.py(9)<module>()-> test(1)s单步跟踪,进入函数(Pdb) s--Call--> f:\python\pdb\test.py(1)test()-> def test(a):c继续运行在 a==7 条件断点处停止p a此时,打印a的值为7(Pdb) c > f:\python\pdb\test.py(2)test()-> while True:(Pdb) p a7a打印所在函数参数(Pdb) a a = 7l查看运行到某处代码(Pdb) l   1     def test(a):  2 B->     while True:  3             if a > 10:  4                 break  5             a += 1  6         return a  7     if __name__ == '__main__':  8         test(1)[EOF]quit退出

sublime设置

sublime设置快捷键F5为运行,Ctrl+F5调试。就会对python调试方便很多。

Package Control中下载SublimeREPL(Read-Eval-Print-Loop)Preferneces -> Key Bingdings-User进行设置[  {"keys": [  "f5"],"caption": "SublimeREPL: Python - RUN current file","command": "run_existing_window_command","args": {  "id": "repl_python_run",  "file": "config/Python/Main.sublime-menu"}  },  {"keys": [  "ctrl+f5"],"caption": "SublimeREPL: Python - PDB current file","command": "run_existing_window_command","args":{    "id": "repl_python_pdb",    "file": "config/Python/Main.sublime-menu"}  }]