A Hands On Exercise in Python DebuggingBefore we even begin, here's how look it up for yourself:Useful Resourceshttp://docs.python.org/library/pdb.html - the official pdb documentation http://openp2p.com/pub/a/python/2005/09/01/debugger.html - lengthy O'Reilly article http://pythonconquerstheuniverse.wordpress.com/category/the-python-debugger/ - concise blog entry about the basics http://aymanh.com/python-debugging-techniques - broad debugging blog entry SECRET - the long form of this presentation/tutorial! I'll provide URL at the end. In-Talk Codemean.py def mean(first, second): result = first + second / 2 return result shouldbe = 6 m = mean(4, 8) print("mean(4,8) =", m) print("should be:", shouldbe) print("correct?", m==shouldbe) sequence.py print(1) print(2) print(3) import pdb; pdb.set_trace() print(4) print(5) print(6) print(7) nested.py def top(): a = 12 b = 3 print("Hello") middle() print("done!") def middle(): a = 0 c = 9 print("world") bottom() def bottom(): d = 88 print("!") top() divide (for mean.py) def divide(x, y): a = 3 / x b = 4 / y return a + b callself.py import logging def callself(a=0): logging.debug(a) a = a + 1 print(a) if a < 10: callself(a) Outline
|