import pdb; pdb.set_trace()
pdb
next
: execute current linestep
: execute current line and stop as soon as possiblecont
: leave the debugger and let your program continue executing python -m pdb django runserver
pdb.run
pdb.run("print('Hey')")
pdb.runcall(int, '4')
python -m pdb
), you get a post mortem debugger after uncaught exceptions (Pdb) args # prints args to current function
(Pdb) list # lists 5 lines before and after current point
(Pdb) ll # long listing: just the current function/method
(Pdb) pp var # pretty-print var
!
(Pdb) b+c
Error: ...no +c on path. whaaaat? PDB thinks you want to set a breakpoint at "+c"
(Pdb) !b+c
[value]
(Pdb) where # where am I in the call stack? last line is where we are
(Pdb) up # move up the stack
(Pdb) down # move down the stack
Effectively acts like a top-level, bare exception handler
import sys
def main():
# stuff
if __name__ == '__main__':
try:
sys.exit(main())
except:
import pdb; pdb.pm()
Way to look at code without editing it; good for third-party stuff
(Pdb) break pfcalc.rpn_app # can break at some callable
(Pdb) break pfcalc.py:41 # ...or a line number
(Pdb) break # show all breakpoints and how many times they've been triggered
Can make breakpoint conditional: only break if python expression is truthy
(Pdb) break pfcalc.rpn_app, environ['HTTP_METHOD'] != 'GET'
alias dr pp dir(%1)
alias loc locals().keys()
alias printdict for key, value in %1.items(): print("{0}: {1}".format(key, value)
next
, step
, end
(Pdb) commands 1
(com) pp self.state
(com) pp value_or_operator
(com) continue
.pdbrc
Hooray!!!pdb