Here’s the code that we wrote before, and now instead of just running it, I’m going to press the green bug symbol because we want to debug this little script that we wrote. Okay, so once I press this bug, we can see that the code that it’s currently looking at is getting highlighted in yellow. Down here in the shell, we see that we’re debugging this
script file that we wrote. Okay.
00:41 If you have a different structure and bigger blocks, then it’s going to just take you to the next bigger block. And now the interesting part. If we go inside, so we Step Into, it’s going to evaluate every piece in itself and show us the output.
I really, really love seeing this feature because it’s a great starter feature. Here, it’s highlighting the code block that it’s currently looking at, so it’s looking at
range(5). And I’ll show you by pressing forward, it’s telling us—okay, now it’s looking at
and we can see that this is what it actually creates, because we know that
range() has this option of giving a start and an end, and if you don’t put a start, then it just takes
0 as the start by default.
And here we can actually see that this happens. So it evaluates in this way that it’s looking at the blocks—
range(5) and then—this is what it comes up with, this is the result. It’s going to be a range that starts at
0 and goes up to
Up to but not including
5. So, we continue stepping. Now we know that the first thing it’s looking at is the
0. If I keep stepping, it’s going to take a look at this expression here—it’s going to start evaluating it.
And that’s one full loop through this. Now, if you keep going, we’re at the next one.
range() has already evaluated the next value that it has, that it looks at—it’s
1. So we’re going to go through the same thing again, with
1 as the value for
03:31 But you can see at every step in the program what’s happening, what is it evaluating, what does it return, what’s the value at the moment—and this is just visually right in your code, and very easy to understand what’s happening through these highlights and step-by-step process.
03:47 I really like this because I think it’s a great way of starting to debug, as well as if there’s actually a bug in your program or also just in a way that I’m doing it now, to step through your program and understand what is happening in there at each step. So yeah, this is a very, very helpful feature in Thonny, and I would very much suggest it for beginners to do this a lot.
04:09 Just get familiar with debugging, think of it as a tool to step through your code and figure out what’s actually going on. It helps you get into the process of thinking about what’s happening in this code.
04:20 Like here, we have a focus on something and it evaluates to something, another focus on something—this expression—it evaluates to something. And just this way of thinking, seeing it visually in this debugger, is extremely helpful. Okay, so I’ve talked enough about this now. That’s debugging in Thonny.
04:37 There’s more that you can learn about it, obviously, but I hope this is going to give you a good idea of what’s possible and maybe entice you to get started working with this, especially when you’re a beginner, but also actually at any level it can be very helpful to visually debug your code. All right! In the next video, we’re going to look a little more at some other useful features that Thonny has to offer. See you over there.
Become a Member to join the conversation.