Show Menu
Cheatography

Python Debugging Cheat Sheet (DRAFT) by

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Python 3.7

breakp­oint()
Start debugger inside a Python script
PYTHON­BRE­AKP­OINT=0
Env Var: Set to skip all breakp­oints
PYTHON­BRE­AKP­OIN­T=i­pdb.se­t_trace
Env Var: breakp­oint() which debugger to use

Getting Started

import pdb;pd­b.s­et_­trace()
Start pdb inside a python script
python -m pdb <fi­le.p­y>
Start pdb from the command line
import ipdb;i­pdb.se­t_t­race()
Start ipdb inside a python script

Help or Exit

h(elp)
show help
q(uit)
or
ctrl+d
quit debugging
 

Manual Breakp­oints

b(reak)
show all breakp­oints
b(reak) line_no
set a breakpoint at a line
b(reak) line_no, condition
set a breakpoint at a line, if condition is met

Stepping

n(next)
step over
s(tep)
step into
r(eturn)
continue until current function returns
c(ontinue)
continue until next breakpoint
j(ump) line_no
next line to be executed (useful for breaking out of loops)
 

Frame Navigation

u(p)
up one level in the stack trace
d(own)
down one level in the stack trace

Display

p(rint) expr
print the value of expr
pp expr
pretty print the value of expr
w(here)
print the current position and stack trace
l(ist)
print the lines of code around the current line
a(rgs)
print args of the current function

credits

original sheet from: github.co­m/K­ape­li/­che­ats­heets