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

2017 - Peter Hadlaw - Intro to pdb

Db2ee812bdc6fd057f8f4209c08b6f63?s=47 PyBay
August 13, 2017

2017 - Peter Hadlaw - Intro to pdb

Db2ee812bdc6fd057f8f4209c08b6f63?s=128

PyBay

August 13, 2017
Tweet

Transcript

  1. INTRO TO pdb Peter Hadlaw @ Tesorio August 13, 2017

    https://www.tesorio.com/careers
  2. TOO OFTEN I SEE... print foo print foo['bar'] print fizz.buzz()

    ...
  3. CONS: Limited (can't interrupt execution) Messy (lot's of clean up)

    Zero interactivity (need to modify code and run everything again) Much harder to dive deeper into third party code (internal or external alike)
  4. DEBUGGER Exist in many languages and platforms Python's built-in debugger

    is... "A computer program that assists in the detection and correction of errors in computer programs."
  5. pdb

  6. THREE EASY STEPS 1. Set a breakpoint 2. Run program

    3. Execution halts at breakpoint and now, you, interact
  7. SETTING A BREAKPOINT import pdb; pdb.set_trace() Using a one liner

    is a nice habit to make clean up easier (e.g. a single dd in vi).
  8. api.py

  9. RUN PROGRAM

  10. l - LIST COMMAND

  11. EXPRESSIONS

  12. n - NEXT COMMAND

  13. s - STEP COMMAND

  14. c - CONTINUE COMMAND

  15. GENERAL FLOW Use l to orient yourself and inspect what

    code is currently being executed. Use n to step forward in execution Use s to dive deeper Create expressions for the debugger to evaluate and gain insights into what's happening c to continue execution until next breakpoint / finish Profit.
  16. NOTES More commands and features available iPython version, much more

    powerful (has to be installed separately) Other languages have debuggers to, for example JavaScript in the browser, or C (gdb)
  17. WE'RE HIRING https://www.tesorio.com/careers