150 likes | 393 Views
Debuggers in Python. The Debugger. Every programming IDE has a tool called a debugger. This application does NOT locate or fix your bugs for you! It slows the program down by letting you ‘single-step’ through it You can check your understanding of the code as it goes by
E N D
The Debugger • Every programming IDE has a tool called a debugger. • This application does NOT locate or fix your bugs for you! • It slows the program down by letting you ‘single-step’ through it • You can check your understanding of the code as it goes by • It shows you the variables that are created and their values • It shows you the call stack of function calls that have been done
Breakpoints • In order to step through your program one statement at a time, you must first set a breakpoint. • If your program is a straight sequence, you may need only one. • If you have branches and loops, you may need several to make sure the execution does actually hit one. • When the program is running under the Debugger, it will run normally (at normal speed) until a breakpointed statement is about to execute. Then the interpreter gives control to you the programmer, it pauses the program and shows the current state of the program.
Stepping • Step Over (Over in IDLE) • “the next statement to execute has a function call in it, I do NOT want to see the details of that call. Just do the call and pause at the next statement” • Step Into (Step in IDLE) • “The next statement to execute has a function call in it, I DO want to see the details of that call. Get to the top of the function definition and pause” • Step Out of (Out in IDLE) • “I have stepped into a function which I did not meant to. Please finish the function call quickly and then pause”
Watch window • For your debugger, check to see where the watch window is • That is where the variables are shown as they are defined and destroyed • Their value is shown, usually their type • When you step through a statement, watch this window to see how a variable changes • In IDLE the window is labeled “Locals” • In WingIDE it is labeled “Stack Data”
Call stack • This keeps track of the current function call • In WingIDE it is a window usually to the right which grows downward as more functions are called • In IDLE it is the list of statements that is in the main Debug window, it also grows downward as more functions are called – it is NOT labeled “call stack”