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
import pdb

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


Flattr this

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: Logo

You are commenting using your 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