always worry about is the debugging of Python, before writing C are compiled with GDB directly debugging, relaxed and happy. Now it's an interpretive program that doesn't know what to do. With log bar, sometimes is a small program, do not want to write so much code, play screen bar, sometimes the screen turned fast, but also very depressed. Today finally good, saw a useful thing,
PDB
method One: Run the python-m pdb myscript.py
(PDB) will automatically stop in the first line, waiting for debugging, you can see the Help
(Pdb) H
explain these key commands
< breakpoint settings
(Pdb) b #断点设置在本py的第10行
or (Pdb) b ots.py:20 #断点设置到 ots.py line 20th
Delete Breakpoint (Pdb) b #查看断点编号
(PDB) CL 2 #删除第2个断点
< operation
(Pdb) n #单步运行
(PDB) s #细点运行 that's going down, method
(Pdb) c #跳到下个断点
< View
(Pdb) p param #查看当前 Variable value
(Pdb) L #查看运行到某处代码
(Pdb) a #查看全部栈内变量
< If the debug on the command line is:
Import PDB
def TT ():
pdb.set_trace ()
For I in range (1, 5):
Print I
<<< tt ()
#这里支持 n P C.
< (3) TT ()
(PDB) n
Python Debug Single-Step debugging