python comes with Debug ToolPak: PDB
#-*-Coding:utf-8-*-def func (num): s = num * return sif __name__ = = ' __main__ ': print ' Debug starting ... ' print ' * ' * print ' debug ending ... ' num = + s = func (num) print s
The PDB library is not referenced in a Python file, and you can add parameters when executing a python file:
python-m pdb demo.py
come to the PDB debug interface, debug mode will stop in the first line of the program code line
The following commands can be executed to perform the appropriate actions:
B (or break): Set breakpoint, set function: b demo.func; set line number: B demo:14 (number of rows)
N (or Next): Executes the next line:Step over, skip
C (or Continue): Executes the next breakpoint, without a breakpoint, to the end of the program: Step filter
s (or Step): Enter function,Step into, single-hop
R (or return): Jump out of function, Step return
L (or list): View the current code snippet
Q (or quit): Exits the current debug
p (or print): Print variable values
h (or help): View assistance
cl (Clear): Clears all nodes
disable [Bpnumber[bpnumber]]: Break the first num breakpoint, enable, fail 10th breakpoint
Enable [Bpnumber[bpnumber]]: Enables the first num breakpoint, enable 10, enables the 10th breakpoint
W (where): Print stack information
A (args): Print the current function parameter information
Of course, we can also use the PDB library function to implement the debug of the py:
For example: we can use the PDB function: Set_trace ()
def func (num): s = num * return sif __name__ = = ' __main__ ': print ' Debug starting ... ' print ' * ' * 10
pdb.set_trace () print ' Debug ending ... ' num = s = func (num)
Execute program: Python pdb_demo.py
This means setting a breakpoint line to the program, which will automatically run to the print ' py ending ... ' Stop and let the developer continue to trigger the next action, which sets the breakpoint just right when a py references another py.