- Published on
Debug in Python
- Authors
- Name
- Loc Truong
Pdb
Start pdb inside a python script
import pdb;pdb.set_trace()
breakpoint()
Start pdb from the command line
python -m pdb <file.py>
# Stepping
n(ext) | Step over |
---|---|
s(tep) | Step into |
r(eturn) | Continue until the current function returns |
c(ontinue) | Continue until the next breakpoint is encountered |
unt(il) line_number | Continue until a specific line is encountered. Or continue until a larger line number is reached if no line_number is set |
u(p) | Up one level in the stack trace |
d(own) | Down one level in the stack trace |
h(elp) OR h(elp) command | Show help |
q(uit) | Quit debugger |
Breakpoint
b(reak) | Show all breakpoints |
---|---|
b(reak) line_number | Set a breakpoint at a specific line |
b(reak) line_number, condition | Set a breakpoint at a specific line, if condition is met |
b(reak) file:line_number | Set a breakpoint in a file at a specific line |
b(reak) func | Set a breakpoint at the first line of a function |
disable number | Disable breakpoint number |
enable number | Enable breakpoint number |
clear number | Remove breakpoint number |
Printing
p(rint) exprpp expr | Print the value of expr |
---|---|
w(here) | Print current position and stack trace |
l(ist)l(ist) start, end | Print 11 lines of code around the current line |
a(rgs) | Print the arguments of the current function |