By Trey Hunner
The file pdb_demo.py
is an interactive demonstration of pdb usage. The
demo will teach you how to use some of the pdb commands shown below. To try
out this demo run it in your Python interpreter:
python pdb_demo.py
This talk started with a demonstration of using pdb to locate a bug in a Django model method. A re-enactment of the demonstration is available on ascii.io.
Below are the pdb commands I usually use. The characters in parenthesis are
optional (so n
and next
to the same thing):
- s(tep)
- n(ext)
- c(ontinue)
- l(ist)
- r(eturn)
Here are some more useful commands:
- a(rgs)
- pp: pretty print
- (q)uit
- (b)reak
Some functions that are generally useful for introspecting Python code:
Some IDEs (PyCharm for example) have built-in Python debuggers that you can use. For more information on alternative debuggers and debugging in your IDE, check out the Python Debugging Tools link below.
- PDB Documentation
- Python Debugging with PDB
- Python Debugging Tools