PDB is an interactive debugging environment for Python programs. It allows you to pause your program, look at the values of variables, and watch program execution step-by-step, so you can understand what your program is actually doing, as opposed to what you think it's doing.
Effectively using PDB is arguably the most important skill a new Python developer can learn. This talk will show novice and intermediate Python users how to use PDB to troubleshoot existing code.
When is it reasonable to use PDB?
"I don't use a debugger"
When is it really not reasonable?
Modes of pdb usage
set_trace mode, e.g. pdb.set_trace()
postmortem mode, e.g.
python -m pdb buggy.py or
run mode, .e.g.
Shortcut aliases (
The workhorse commands (list, print, pretty-print, next, continue, step, return, until, where, up, down):
list: displaying code in your current execution context
pp: displaying objects
where: showing the current location in the frame stack
down: navigating the frame stack
Managing breakpoints (break, tbreak, ignore, enable, disable, clear):
clear: Managing breakpoints
Lesser-used commands (args, !-prefixing, debug)
debug: recursive debugging
!-prefixing: modifying variables
args: printing args to the current function
commands: scripting pdb
~/.pdbrc and PDB aliases
Debugging in the face of threads (ie. web apps).
Enhanced shells: ipdb, pudb, winpdb
In-editor debugger integration (Wing, Eclipse PyDev, PyCharm, etc)