标签:and ace ++ import 命令 cal turn ipy home
pdb是基于命令行的调试工具,非常类似gnu的gdb(调试c/c++)。
def getAverage(a,b): result = a+b print("result is %s"%result) return result a = 10 b = 20 c = a+b ret = getAverage(a,b) print(ret)
程序启动,停止在第一行等待单步调试。
python -m pdb some.py
(Pdb) l #list显示当前的代码 1 -> def getAverage(a,b): 2 result = a+b 3 print("result is %s"%result) 4 return result 5 6 a = 10 7 b = 20 8 c = a+b 9 ret = getAverage(a,b) 10 print(ret) [EOF] (Pdb) n #next 向下执行1行代码 > /home/python/python06/01-调试.py(6)<module>() -> a = 10 (Pdb) l 1 def getAverage(a,b): 2 result = a+b 3 print("result is %s"%result) 4 return result 5 6 -> a = 10 7 b = 20 8 c = a+b 9 ret = getAverage(a,b) 10 print(ret) [EOF] (Pdb) c #继续执行代码 result is 30 30 The program finished and will be restarted > /home/python/python06/01-调试.py(1)<module>() -> def getAverage(a,b): (Pdb) l 1 -> def getAverage(a,b): 2 result = a+b 3 print("result is %s"%result) 4 return result 5 6 a = 10 7 b = 20 8 c = a+b 9 ret = getAverage(a,b) 10 print(ret) [EOF] (Pdb) n > /home/python/python06/01-调试.py(6)<module>() -> a = 10 (Pdb) l 1 def getAverage(a,b): 2 result = a+b 3 print("result is %s"%result) 4 return result 5 6 -> a = 10 7 b = 20 8 c = a+b 9 ret = getAverage(a,b) 10 print(ret) [EOF] (Pdb) b 9 #第9行添加断点 Breakpoint 1 at /home/python/python06/01-调试.py:9 (Pdb) n > /home/python/python06/01-调试.py(7)<module>() -> b = 20 (Pdb) l 2 result = a+b 3 print("result is %s"%result) 4 return result 5 6 a = 10 7 -> b = 20 8 c = a+b 9 B ret = getAverage(a,b) 10 print(ret) [EOF] (Pdb) c > /home/python/python06/01-调试.py(9)<module>() -> ret = getAverage(a,b) (Pdb) l 4 return result 5 6 a = 10 7 b = 20 8 c = a+b 9 B-> ret = getAverage(a,b) 10 print(ret) [EOF] (Pdb) p a 10 (Pdb) s --Call-- > /home/python/python06/01-调试.py(1)getAverage() -> def getAverage(a,b): (Pdb) l 1 -> def getAverage(a,b): 2 result = a+b 3 print("result is %s"%result) 4 return result 5 6 a = 10 7 b = 20 8 c = a+b 9 B ret = getAverage(a,b) 10 print(ret) [EOF] (Pdb) a a = 10 b = 20 (Pdb) q #退出调试
进入python或ipython解释器
import pdb pdb.run(‘testfun(args)‘) #此时会打开pdb调试,注意:先使用s跳转到这个testfun函数中,然后就可以使用l看到代码了
当程序执行到pdb.set_trace() 位置时停下来调试
代码上下文
... import pdb pdb.set_trace() ...
大公司只能用日志调试
标签:and ace ++ import 命令 cal turn ipy home
原文地址:http://www.cnblogs.com/venicid/p/7944662.html