After adding print and executing the script, the inefficient debug method should be completed. If you are familiar with GDB, you should easily accept PDB. Official Document address: http://docs.python.org/library/pdb.html.
There are two ways to use PDB, one of which is to add code in the script. I don't think this method is better than print, so this method is not described in this article. Here we only learn how to use the PDB command line.
1) enter the command line debug mode, Python-m pdb myscript. py
2) h: (HELP) Help
3) W :( where) print the current execution stack
4) D: (down) execute to jump to the deep layer of the current stack (I don't think it is useful)
5) U :( up) the execution jumps to the top layer of the current stack.
6) B: (break) Add a breakpoint
B. list all current breakpoints and the number of times the breakpoint is executed.
B line_no: Add a breakpoint to the line_no line of the current script
B filename: line_no: Add a breakpoint to the line_no line of the script filename
B function: Add a breakpoint to the first executable statement of the function.
7) tbreak: (temporary break) Temporary breakpoint
After the breakpoint is executed for the first time, the breakpoint is automatically deleted. The usage is the same as that of B.
8) Cl :( clear) Clear the breakpoint
CL clear all breakpoints
CL bpnumber1 bpnumber2. .. clear the breakpoint with the breakpoint number bpnumber1, bpnumber2. ..
CL lineno clears the breakpoint of the lineno row of the current script
CL filename: line_no clear the breakpoint of line line_no of script filename
9) Disable: indicates that the breakpoint is disabled. The parameter is bpnumber. The difference between this parameter and Cl is that the breakpoint still exists, but is not enabled.
10) Enable: Enable the breakpoint. The parameter is bpnumber.
11) s :( step) execute the next command
If this sentence is a function call, s will execute the first sentence of the function.
12) n :( next) execute the next statement
If this sentence is a function call, execute the function and then execute the next one of the currently executed statements.
13) r :( return) execute the current running function until the end
14) C: (CONTINUE) continue execution until the next breakpoint occurs.
15) l :( list) list source code
L list 11 codes around the currently executed statement
L first: List 11 codes around line 1
L first second: code used to list the first -- Second range. If Second <first, second will be parsed as the number of rows.
16) A :( ARGs) lists the functions currently executed by the function.
17) P Expression :( print) Output expression value
18) pp expression: A nice P Expression
19) Run: restart debug, equivalent to restart
20) Q: (quit) Quit debug
21) J lineno :( jump) sets the next executed statement Function
You can only jump to the bottom layer of the stack and re-execute it backward. You can directly execute the forward to the row number.
22) unt: (until) execute to the next line (jumping out of the loop), or the current stack ends
23) condition bpnumber conditon: set the condition for the breakpoint. When the condition parameter returns true, the bpnumber breakpoint is valid; otherwise, the bpnumber breakpoint is invalid.
Note:
1: Enter enter directly to execute the previous command;
2: enter a command that is not recognized by PDB. PDB runs the command as a python statement in the current environment;