78

I want to add pdb—the Python debugger—to my toolbox. What's the best way to get started?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Matthew Rankin
  • 457,139
  • 39
  • 126
  • 163

2 Answers2

118

Here's a list of resources to get started with the Python debugger:

  1. Read Steve Ferb's article "Debugging in Python"
  2. Watch Eric Holscher's screencast "Using pdb, the Python Debugger"
  3. Read the Python documentation for pdb — The Python Debugger
  4. Read Chapter 9—When You Don't Even Know What to Log: Using Debuggers—of Karen Tracey's Django 1.1 Testing and Debugging.
Matthew Rankin
  • 457,139
  • 39
  • 126
  • 163
  • Eric Holscher has quite a bit on debugging: [1](http://ericholscher.com/blog/2008/aug/28/screencast-debugging-django-error-page/), [2](http://ericholscher.com/blog/2008/aug/29/screencast-2-logging-fun-and-profit/), [3](http://ericholscher.com/blog/2008/aug/30/using-pdb-python-debugger-django-debugging-series-/) (which you linked to), and [4](http://ericholscher.com/blog/2008/sep/2/using-pdb-debug-management-commands-and-unit-tests/) – Ehtesh Choudhury Feb 26 '14 at 20:09
  • I made a summary nice for getting started in answer https://stackoverflow.com/a/71021836 – user2987828 Feb 22 '23 at 05:05
17

Synopsis:

# epdb1.py -- experiment with the Python debugger, pdb
import pdb
a = "aaa"
pdb.set_trace()
b = "bbb"
c = "ccc"
final = a + b + c
print final

Now run your script:

$ python epdb1.py
(Pdb) p a
'aaa'
(Pdb)
Josh Glover
  • 25,142
  • 27
  • 92
  • 129