Here is how you would use pdb on the command line without implementing anything in your source code (documentation and other online resources do not explain this very well to a programmer who in the past used only visual debuggers):
Run pdb by typing the following at a command prompt:
python -m pdb 'python_script'
This command initializes pdb, and the pdb debugger stops at the first line of your python_script and will wait for input from you:
(Pdb)
This is the interface for communication with the debugger. Now you can specify your teams here. Unlike using buttons or keyboard shortcuts in visual debuggers, here you will use commands to get the same results.
You can go to the next line in your code with the "n" command (next):
(Pdb) n
Doing the following will display the line number and specific code in the source:
> python_script(line number)method name -> current line in the source code
You can set a breakpoint by specifying the line number in the source code.
(Pdb) b 50
Here, the debugger is set to break on line 50. If there are no other breakpoints, the breakpoint on line 50 will be the first, and a breakpoint identifier of 1 can refer to it. If you add more breakpoints, they will get the identifiers sequentially (i.e. 2, 3, etc.)
Once the breakpoint is set, you continue to run the program until pdb reaches the breakpoint as follows:
(Pdb) c
When you reach the breakpoint, you can go to the next line with the n command, as described above. If you want to check the values ββof variables, you must execute the parameter command as follows:
(Pdb) p variable_name
If you no longer need a breakpoint, you can clear it by passing the breakpoint identifier with the clear command:
(Pdb) clear 1
Finally, when you are done with the debugger, you can exit the execution in the same way as from the python command line interpreter.
(Pdb) exit()
I hope this helps anyone get started with pdb. Here is a list of commands you can use with the debugger: pdb, so questions and answers