Home > Developer Tips and Tricks > The Python Debugger (pdb)

The Python Debugger (pdb)

To break into pdb from a running program, insert this right into your code:
import pdb; pdb.set_trace()

You will then be in the debugger prompt, where you can move up/down in your code (u/d), look at variables (p expression), or execute any Python syntax in the current context (eg. changing a variable). A list of debugger commands is here.

To print an object’s complete state, the following can be used:
pp vars(your_object)

Leave a Reply

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 )

Connecting to %s

Follow

Get every new post delivered to your Inbox.