A brief introduction python's handy built-in debugger, Pdb. Presented as a part of the Hackbright Academy summer fellowship.
Size: 331.53 KB
Language: en
Added: Jul 15, 2015
Slides: 13 pages
Slide Content
Debugging Python with Pdb Noelle Daley, 7.13.2015
Debugging numbers = [1, 2, 3, 4, 10, -4, -7, 0] def all_even(l): even_numbers = [] for number in l: if number / 2 == 0: even_numbers.extend(number) return even_numbers all_even(numbers)
One option: all the print statements! for number in l: print "Number is: ", number if number / 2 == 0: print number, " is an even number!" even_numbers.extend(number) print "List now includes:" print even_numbers
Enter Pdb! Pdb is the built-in Python debugger. It helps you debug programs interactively, allowing you to step into functions, test variables, and much more. *not really
Using Pdb Import pdb, then insert where you’d like to start debugging: numbers = [1, 2, 3, 4, 10, -4, -7, 0] import pdb; pdb.set_trace() def all_even(l): even_numbers = []...
Using Pdb
Pdb Commands l (list) -- shows where you are in your script n (next) -- steps to next line of execution (but not into functions!) s (step) -- steps into next line of execution, including functions r (return) -- steps to the end of currently executing function c (continue) -- executes code q (quit) -- exit the debugger ? (help) -- shows all commands
Pbd Commands: l List where you are in the script:
Pbd Commands: n Step to next line of execution:
Pbd Commands: s Step into next line of execution:
Evaluating Variables!!!!!!!!!! 1 / 2 == 0?!
Recap Pdb is awesome! Use it when print statements are cluttering your script. Import: import pdb; pdb.set_trace() Navigate with l , n , and s .
Resources Debugging in Python - Python Conquers the Universe Python Docs - the Python Debugger Tutorial: Debugging Python apps with Pdb