all Python 3pdbterm
pdb
module
Python's built-in debugger: stop at a point, step through code, inspect variables and the stack.
Syntax
import pdb
pdb is usually started not by import but with the built-in breakpoint() or by running python -m pdb script.py; after a crash, post_mortem opens the debugger where the exception happened. Inside are short commands: n for the next line, s to step into a call, p to print an expression, c to continue. Trap: a one-letter variable named like a command (n, c) is shown only with p n, otherwise the command runs.
Examples
import io, pdb
out = io.StringIO()
dbg = pdb.Pdb(stdin=io.StringIO('next\np x * 10\ncontinue\n'), stdout=out)
dbg.use_rawinput = False
dbg.run('x = 4\ny = 5')
print(out.getvalue().splitlines()[2]) # → (Pdb) 40
See also
Open in the full glossarydocs.python.orgReport an inaccuracy