Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set the default subtitles language in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

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.

00:17 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:01 But when I’ve highlighted the interactive window, then you can see that there’s the Debug option. Now go ahead and select Debug and Debugger.

01:13 You can see the string [DEBUG ON] popping up, and also the Debug Control window appears.

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.

01:35 Next you’ll explore the interface of the Debug Control window by writing and running a short program that has no bug for a start. for i in range(1, 4):

01:52 j = i * 2. And then you can print out an f-string

02:01 that just gives you information about these two variables, i is and then the value of i, and j is and then the value of j.

02:15 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:42 And once you’ve started to run your program, you might notice that it doesn’t get very far. It stops and the Debug window highlights, and you can see a message appear here in the Stack window.

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.

03:20 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.

03:39 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.

05:04 They start with these double underscores (__). You have __annotations__, __builtins__, __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.

05:52 And finally to complete our walkthrough of the Debug Control window interface, at the top you have five buttons: Go, Step, Over, Out, and Quit.

06:06 These buttons allow you to interact with the debugger and step through your code. They do slightly different things, and you will explore exactly what the buttons do in the upcoming lessons.

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 Overand you will use them to inspect your code in more detail.

Become a Member to join the conversation.