This post tells you how to debug python script using pdb in terminal ( command line). Simplyfy your debugging work using this quick tutorial along with commands.
Here you can set and clear the breakpoints. And, you can set values to variables. Keep handy the listed commands. Here is How to avoid syntax errors in python.
To start debugging, you need a ‘pdb’ package in Python.
Refer to my example Python script – sample.py. Here, you are importing pdb and executing the debug.
$python -m pdb sample.py
How to use ‘pdb’ in Command Line to Debug Python Script
Python ‘pdb’ Debugging Commands.
1. Command to List source code:
l – it displays 11 lines of source code
ll – it display entire source codes
2. Command to Set break point:
b 10 – it sets break point at line 10.
3. Command to Continue:
c – it continues execution.
4. Command to debug line by line:
s – just executes one line.
5. Command to Execute next line.
n – it executes next line.
6. Command to Execute up level:
u 10 – execution up 10 lines.
7. Command to Execute down level:
d 10 – execution down 10 lines.
9. 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.