Upgrade to Pro — share decks privately, control downloads, hide ads and more …

So You Think You Can PDB?

So You Think You Can PDB?

This talk will be an introduction to the most commonly used Python Debugger commands and what they do. Learn how to navigate and inspect code from the pdb prompt so you can better understand how it works. The Python Debugger is a valuable debugging tool for all levels of Python programmers. You should walk away being able to debug the next Python code you encounter!

Clayton Parker

April 11, 2015
Tweet

More Decks by Clayton Parker

Other Decks in Programming

Transcript

  1. So You Think You Can PDB? Clayton Parker So You

    Think You Can PDB? - Clayton Parker - PyCon 2015
  2. How to invoke it? Set a trace directly in the

    code: import pdb; pdb.set_trace() Or start a script with pdb directly: $ python -m pdb example.py It is that easy!
  3. Help Type help or ? for short to know what

    commands are available Further help on commands help help or help list
  4. Show the current context Type list or l to see

    the current position in the code
  5. Examine variables Type print or p to see what a

    variable is set to Use pp to pretty print the result for easier reading
  6. Step into a function Type step or s to step

    into a function for further inspection
  7. Skip to the end of a function Type return or

    r to go to the end of a function
  8. Breakpoints Type break or b to see a list of

    breakpoints Then b and a line number to set one To clear out a breakpoint clear or cl and a breakpoint number
  9. Continue execution Type continue or c to go to the

    next breakpoint or finish execution
  10. See where you are in the stack Type where or

    w to see the current stack You can debug at any point in the stack
  11. Traverse the stack Type up or u to go up

    the stack Type down or d to go back down the stack
  12. New features in Python 3: Interact Type interact to open

    an interpreter in the current scope
  13. New features in Python 3: Long list Type longlist or

    ll to show the complete current function