首先准备一段有问题的python代码,如下:
# cat test.py
# 摘自:DevOps 和自动化运维实战一书
#! /usr/bin/env python
s='0'
n = int(s)
print (10/n)
使用python -m pdb 进入调试交互模式,常用指令如下
l: 展示所有源码内容;
n: 单步执行;
p +变量名:打印变量的值;
exit: 退出调试;
$ python -m pdb test.py
> c:\users\11470\desktop\test.py(2)<module>()
-> s='0'
(Pdb) l
1 #! /usr/bin/env python
2 -> s='0'
3 n = int(s)
4 print (10/n)
[EOF]
(Pdb) n
> c:\users\11470\desktop\test.py(3)<module>()
-> n = int(s)
(Pdb)
> c:\users\11470\desktop\test.py(4)<module>()
-> print (10/n)
(Pdb) p s
'0'
(Pdb) p n
0
(Pdb)
0
(Pdb) n
ZeroDivisionError: division by zero
> c:\users\11470\desktop\test.py(4)<module>()
-> print (10/n)
(Pdb) exit
标签:python,py,Pdb,11470,test,desktop,pdb,调试 From: https://www.cnblogs.com/o-O-oO/p/18604707