15 调试
1. pdb
pdb是基于命令行的調(diào)試工具,非常類似gnu的gdb(調(diào)試c/c++)。
def getAverage(a,b):result = a+bprint("result is %s"%result)return resulta = 10 b = 20 c = a+b ret = getAverage(a,b) print(ret)?
?
2.執(zhí)行時調(diào)試
程序啟動,停止在第一行等待單步調(diào)試。
python -m pdb some.py?
?
?
(Pdb) l #list顯示當(dāng)前的代碼1 -> def getAverage(a,b):2 result = a+b3 print("result is %s"%result)4 return result5 6 a = 107 b = 208 c = a+b9 ret = getAverage(a,b)10 print(ret) [EOF] (Pdb) n #next 向下執(zhí)行1行代碼 > /home/python/python06/01-調(diào)試.py(6)<module>() -> a = 10 (Pdb) l1 def getAverage(a,b):2 result = a+b3 print("result is %s"%result)4 return result5 6 -> a = 107 b = 208 c = a+b9 ret = getAverage(a,b)10 print(ret) [EOF] (Pdb) c #繼續(xù)執(zhí)行代碼 result is 30 30 The program finished and will be restarted > /home/python/python06/01-調(diào)試.py(1)<module>() -> def getAverage(a,b): (Pdb) l1 -> def getAverage(a,b):2 result = a+b3 print("result is %s"%result)4 return result5 6 a = 107 b = 208 c = a+b9 ret = getAverage(a,b)10 print(ret) [EOF] (Pdb) n > /home/python/python06/01-調(diào)試.py(6)<module>() -> a = 10 (Pdb) l1 def getAverage(a,b):2 result = a+b3 print("result is %s"%result)4 return result5 6 -> a = 107 b = 208 c = a+b9 ret = getAverage(a,b)10 print(ret) [EOF](Pdb) b 9 #第9行添加斷點 Breakpoint 1 at /home/python/python06/01-調(diào)試.py:9(Pdb) n > /home/python/python06/01-調(diào)試.py(7)<module>() -> b = 20 (Pdb) l2 result = a+b3 print("result is %s"%result)4 return result5 6 a = 107 -> b = 208 c = a+b9 B ret = getAverage(a,b)10 print(ret) [EOF] (Pdb) c > /home/python/python06/01-調(diào)試.py(9)<module>() -> ret = getAverage(a,b) (Pdb) l4 return result5 6 a = 107 b = 208 c = a+b9 B-> ret = getAverage(a,b)10 print(ret) [EOF](Pdb) p a 10 (Pdb) s --Call-- > /home/python/python06/01-調(diào)試.py(1)getAverage() -> def getAverage(a,b): (Pdb) l1 -> def getAverage(a,b):2 result = a+b3 print("result is %s"%result)4 return result5 6 a = 107 b = 208 c = a+b9 B ret = getAverage(a,b)10 print(ret) [EOF] (Pdb) a a = 10 b = 20 (Pdb) q #退出調(diào)試?
3.交互調(diào)試
進入python或ipython解釋器
import pdb pdb.run('testfun(args)') #此時會打開pdb調(diào)試,注意:先使用s跳轉(zhuǎn)到這個testfun函數(shù)中,然后就可以使用l看到代碼了?
?
4.程序里埋點
當(dāng)程序執(zhí)行到pdb.set_trace() 位置時停下來調(diào)試
代碼上下文 ...import pdb pdb.set_trace() ...?
?
5.日志調(diào)試
? 大公司只能用日志調(diào)試6.集成開發(fā)環(huán)境IDE
?
轉(zhuǎn)載于:https://www.cnblogs.com/venicid/p/7944662.html
總結(jié)
- 上一篇: 微信小程序与Java后台的通信
- 下一篇: 建行分期通到哪能刷?刷不出来怎么办?