Python's own 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 can be used when running a python file with a number of parameters:
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 ability to run the following command, for example:
B (or break): sets a breakpoint. Set function: b demo.func; set line number: B demo:14 (number of rows)
N (or Next): Run the next line:Step over, skip
C (or Continue): Runs 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): Clear all nodes
disable [Bpnumber[bpnumber]]: The first num breakpoint is invalidated. Enable Failure 10th Breakpoint
Enable [Bpnumber[bpnumber]]: Enables the first NUM breakpoint, enabling 10. Enable 10th Breakpoint
W (where): Print stack information
A (args): Print 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)
running the program: Python pdb_demo.py
This means setting a breakpoint line to the program. Will voluntarily execute to print ' py ending ... ' Stop, let the developer continue to trigger the next action. This operation is PY other reference py when, just set a breakpoint advantage.
Copyright notice: This article blog original article. Blogs, without consent, may not be reproduced.
Linux simple debug Python plan by using PDB