Python Debugger Cheatsheet
Getting started Movement
start pdb from within a script: <ENTER> repeat the last command
import pdb;pdb.set_trace()
n(ext) execute the current statement (step over)
start pdb from the commandline:
python -m pdb <file.py> s(tep) execute and step into function
r(eturn) continue execution until the current function returns
Basics
c(ontinue) continue execution until a breakpoint is encountered
h(elp) print available commands u(p) move one level up in the stack trace
h(elp) command print help about command
d(own) move one level down in the stack trace
q(quit) quit debugger
Breakpoints
Examine
b(reak) show all breakpoints
p(rint) expr print the value of expr
b(reak) lineno set a breakpoint at lineno
pp expr pretty-print the value of expr
w(here) print current position (including stack trace) b(reak) func set a breakpoint at the first line of a func
l(ist) list 11 lines of code around the current line
l(ist) first, last list from first to last line number Manipulation
a(rgs) print the args of the current function !stmt treat stmt as a Python statement instead of a pdb command
by Florian Preinstorfer (nblock@archlinux.us) — version 1.0 — license cc-by-nc-sa 3.0
see https://github.com/nblock/pdb-cheatsheet for more information.