all Python 3pdbterm
pdb.Pdb
running under the debugger
The pdb debugger class. You create your own instance to set where commands come from and go to, modules to skip, or the backend.
Syntax
pdb.Pdb(completekey='tab', stdin=None, stdout=None, skip=None, nosigint=False, readrc=True)
Commands need not come from the keyboard: stdin=io.StringIO('n\np x\nc\n') runs a script without a person, and stdout collects the answers. By default readrc=True reads ~/.pdbrc and .pdbrc in the current directory, so a forgotten file there runs commands silently; use readrc=False for reproducible runs. skip=['json.*'] keeps it from stepping into frames of those modules.
Examples
import io, pdb
def area(w, h):
s = w * h
return s
out = io.StringIO()
dbg = pdb.Pdb(stdin=io.StringIO('n\np s\nc\n'), stdout=out, readrc=False, nosigint=True)
print(dbg.runcall(area, 3, 4)) # → 12
print(out.getvalue().split('(Pdb) ')[2].strip()) # → 12 — ответ на команду p s
See also
Open in the full glossarydocs.python.orgReport an inaccuracy