IDLE's Debug Control Window
00:00 The main interface to IDLE’s debugger is the Debug Control window, which we’ll refer to as the Debug window for short. You can open the Debug window by selecting Debug/Debugger from the menu when you are in an interactive window.
You can then look for the string
[DEBUG ON] next to the prompt in the interactive window. That will show you that the debugger is running. Note that the Debug menu is only visible when you’re actually in the interactive window, but not when you’re in the editor window. Now, what does that mean? Let’s head over to IDLE and take a look.
00:44 Here, I am in an IDLE session, and I have an editor window open on the left, and I have an interactive window open on the right. I will show you that when the editor window is selected, then I cannot see the Debug window up in the menu.
01:23 Now I’ve rearranged the windows so I have my editor in the top-left, the interactive window in the bottom-left, and then the Debug Control window here filling up the whole right side of the screen.
Now you need to save this first before you can run it. So I will do that using Command + S, or Control + S if you’re on Windows, and once your file is saved, and you can confirm that the debugger is on by looking at the
[DEBUG ON] message in the prompt of your interactive window, then you can run the script, for example by pressing F5.
02:56 Now let’s explore the interface of this Debug window. I’ve just mentioned that you can see the Stack window here that highlights the line of code. You can switch it on and off with the checkbox at the top—you see these four checkboxes, and one of them is called Stack, and this one you can switch on and off the Stack window.
And now let’s take a look what you can see in here. What does this line that is highlighted actually mean? If you read it out, you can see it says
'__main__'.<module>(), line 1:
for i in range(1, 4):. So this might sound familiar.
If you look over to your script, you can see that in line 1, you’re actually saying
for i in range(1, 4):. So this is where your debugger stopped, and you don’t even need to highlight this yourself, but you can check one of the other checkboxes at the top of the Debug Control window, and that is the Source checkbox. If you check it, then IDLE will automatically highlight the current line that the debugger is looking at.
04:09 And what this means is that line 1 is about to be executed. It hasn’t run yet. So the debugger stops just short of executing line 1 and tells you about it, that this is what it’s going to do next.
04:25 So inside of the Stack window, you can always see what is going to be the next line that will run. And if you have the Source checkbox checked, you can also see it in your script, in the source code.
04:39 Next, take a look at what’s underneath the Stack window, and to avoid confusion, I want you to first check the Globals checkbox as well. You may see that whatever was before at the top now jumped into the Globals section of the Debug window. And in here, you can see there’s a bunch of variables that are somewhat strange looking.
They start with these double underscores (
__). You have
__doc__, et cetera, and these are variables that Python defined in the global namespace of your script. You don’t need to worry about them.
05:21 They are just variables that Python always defines when running a new script. And inside of this Globals variable inspector, you can see how your variables will change over the course of your program.
05:35 The Locals panel just above the Globals panel does the same, but for local variables. If you will open up a local scope—for example, in a function—and define variables in there, then these variables will show up in the Locals panel.
06:19 This completes the overview of the Debug Control window. You checked out all the options that exist on here, and in the next lesson, you will start using some of the buttons—specifically, Step, Out, and Over—and you will use them to inspect your code in more detail.
Become a Member to join the conversation.