This post tells you how to debug python script using pdb in terminal ( command line). Simplify your debugging work by using this quick tutorial along with commands.
During debugging, you can set and clear the breakpoints. And, you can set values to variables. Below, I have listed useful commands. Here is How to avoid syntax errors in python.
How to debug using ‘pdb’ debugging-utility?
- Install ‘pdb’ package in your Python interpreter
- The usage of ‘pdb’ explained in Video
- Top pdb commands
1. Install ‘pdb’ package.
Refer to my example Python script – sample.py. Here, you are importing pdb and executing the debug.
$python -m pdb sample.py
2. The usage of ‘pdb’ debugging-utility.
3. Top ‘pdb’ Debugging Commands.
a. Command to List source code:
l – it displays 11 lines of source code
ll – it display entire source codes
b. Command to Set break-point:
b 10 – it sets break point at line 10.
c. Command to Continue:
c – it continues execution.
d. Command to debug line by line:
s – just executes one line.
e. Command to Execute next line.
n – it executes next line.
f. Command to Execute up level:
u 10 – execution up 10 lines.
g. Command to Execute down level:
d 10 – execution down 10 lines.
h. Command to Quit from debugger:
q – to quit from debugger.
12 Python Top Interview Questions
These questions useful for your next interview and to use in your project.