The beauty of Pdb

I never used Pdb much. I always thought that I had to run my whole script through the debugger, set some breakpoints through obscure commands and whatnot. But it is not the case. I can do simply this:

#!/usr/bin/env python
do_some_stuff()
import pdb
pdb.set_trace()
do_some_other_stuff()

Now you run your script as usual, and it stops at the pdb.set_trace() line and opens up a Pdb prompt. Then you can go line by line, explore and set variable contents and find out the source of your problem. Great! This approach is convenient and easy to use.

You need to know just a several basic commands to be able to do quite a lot in the Pdb shell. Read this 10-minute introduction, it’s worth it: Debugging in Python

Enjoy.

Flattr this

Advertisements
The beauty of Pdb

One thought on “The beauty of Pdb

Leave a Reply (Markdown syntax supported)

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s