Debug is an important debugging technique for coding, which helps developers understand the running process better by setting breakpoints during operation.
Debug in Python is not as intuitive as setting breakpoints in the IDE like Java or C + +.
There are two ways to debug Python: 1. Run in the command line , 2. Run in the script . Both methods require the use of a PDB module.
Mode one: Run on the command line
$ python-m pdb my_script.py
Mode two: Run in script
Where breakpoints need to be set, insert method pdb.set_trace ()
Import PDB def make_bread (): pdb.set_trace () return"I don ' t have time "print(Make_bread ())
Command: After entering the debug state, you can enter the command to debug.
C: (continue) Continue W: (words) Displays the context information for the current line A: (arguments) Prints the argument list of the current function S: (stop) executes the current line and stops at the top one possible time N: (next) Continue execution until the next line of the current function or the function returns a value
How to debug in Python