Python ‘pdb’ Tutorial to Debug at Command Line

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

How to debug .py module using pdb in Python

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.

References

List of top debugger Commands in Python.

12 Python Top Interview Questions

These questions useful for your next interview and to use in your project.

Related Posts

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.

Start Discussion

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.