In this lecture, I'd like to show you some of the other capabilities of Sony in particular relating
to debugging that a lot of people are asking about.
I've got to say that these features are not really available for micro python programming on the episode
of two, but they are available for general purpose, Python and for desktop version of Python.
And I'm going to use that for examples that are coming up.
Again, these are not features that we are going to be using later on in this course, but things that
people do ask about.
And I just wanted to make sure that you've got a good understanding of the Sony ID, Ed, before we
get on with my python.
So I have already opened up the via Ghosheh and Stack Winderlich.
You can do that by going to view and choose the window that you want to open up the service, for example,
the program tree that you can see down here.
And let's have a look at your object, inspector and so on.
I'm not going to go through all of them because then we are going outside of the scope of this course,
which is to focus on micro python.
And before I start with my small demonstration, I also want to point out that if you go to these Thorney
dot org website, it's a very homepage.
There's a demo video here which I have mentioned previously.
You should really take a look at it will give you a really good overview of those features.
And I'm also going to touch upon in this lecture.
OK, so I'm going to turn off the object inspector and the program that really need it.
And I'm going to switch my targeted interpreter to the default one, because, as I said, these features
don't work with the especially to micro python version.
So now we are running Python three point seven point.
And I got a little program here that just adds to numbers of code number one.
And number two, just a couple of arbitrary random numbers.
You can also use the input function to allow you to enter those numbers during runtime.
But let's keep things simple then.
I've got a calculation happening here.
The result goes into the some variable and print out the results onto the show like this.
And I'm using the format function to talk more about this in Section five, which is fairly detailed
introduction to Python.
So there were better details about what this does.
What is important right now is what the output is.
So you run this program and you see that the output is just the sum of the calculation with a bit of
information about what was calculated by the component of the calculation.
Now, see what happened as soon as they executed the program is that the variables tab became populated
with the numbers you can see here that have got the value idea, which is this is a memory location
where no one is stored.
And number two, and some also have the heap.
Memory in the stack is empty and a hidden memory is where both he and Stack are stored in Ram Python
in particular uses heap and stack differently.
So it said both are part of their end.
But in memory, Python is going to store the global variable she can see here.
No one is a global variable and stored at this remote location.
c.B zero, and that matches this idea here in the heap, which has this value one point five as it was
assigned here, and line number three in the script.
And similarly, number four line declares initializes variable number two, which you can see here.
This is its value add in RAM, which is right here in the heap.
Again, here is where Python stores its global variables.
You've got some which was created later and its content are the result of the addition between number
one and number two.
We don't have anything in the stack because we don't have any functions.
So let me show you an alternative of this little simple program.
So here I've got the exact same thing happening, but now I've got a function declared called add numbers.
And again, don't worry about the details.
I'm going to talk about how to create functions in Section five of this course.
But you'll see that we've got the global variables.
We've got some variable created here, and then we've got a call to the function at numbers.
So essentially the program jumps from here to here and then we're going to line number five and execute
it.
Now, if I run this program, see what happens.
So after the execution of the program, one thing that we didn't really see was what happened in this
attack, if at all.
So this attack, as I said earlier, is where Python keeps track of its position in the program.
Trees are especially useful when we have to go from one part of the program and continue with the execution
of the program inside a function.
So for Python to know where to return once the execution of the function is complete, it needs to keep
track of the origin of the call inside the stack and to be able to see the start getting populated.
I'm going to use the debug function first.
I'm going to have a little line stop here.
Just double click on the line where I want the execution to stop temporarily and then I'm going to click
on the current screw button and that will start executing the program.
But they will stop at the location where I've got the red dot, the stop line, and you can see that
I've got my variables here, the global variables.
I've got my head exactly as we did earlier.
Now we've got an additional component in the heap.
We've got the function ID numbers.
So the program does know about it.
And I can continue the execution of the program by using one of those patterns here.
So step over, step into and step out, step over allows me to move on to the next line of the program
without actually drilling in into the individual components that make up this line of code instead of
going stepping over.
I'm going to go step into to explain more about what I'm talking about here, to remember that we are
now executing line 15.
And I'm going to step in to and you can see that now with step into the execution continues into the
right side of the equals sign.
And if I click on Step into again, it drops further into the first component of this edition.
And it will evaluate that you can see that it will change it into its I.D., so Vago no one now has
been replaced in the code itself with its value I.D., which you can see the variables tab.
And also in the caps, you can see it's actually assigned value.
Do one more step in two and then it goes over to the other side and have a look at the number.
And again, you can guess if I click on it again, it's going to into the number and replace it with
its eyeteeth.
But instead I'm going to go and do a step over and that is going to skip it and start exiting.
And until eventually the whole thing, the sum of these two numbers is replaced by the idea where those
numbers are stored, which is B three zero seven point eight.
And it's just about again, it's going to jump into line nineteen.
Now, look what happens here.
As soon as I went into line 19, what is the call to the add numbers function?
The stack keeps track of that.
The stack now keeps track of where I'm going to jump into another part of the program, which happens
to be a function so that this is where I'm going to return or the problem is going to return to once
the function execution is complete and it's going to step over there and be finished.
So it's not going to go into the function because I did a step over when to do one more thing here.
And I'm going to say Trent finished
like that and I'm going to execute again.
And using the debugger this time, I'm going to go for that over for the first time and then I'm going
to do step into four to do that.
I'm going to open up the stack.
When you can see that the module line 19 is in the first position of the stack them I'm going to step
into now drilling into the function.
And now this is interesting.
You see that a new window popped up because now we have drilled into the add numbers function.
So a new window popped up to show us what is happening inside that function.
And you can see there are another entry has been made into the stack.
This is now line five, which is the line that we are executing right now so as to step into again,
see drilling into the individual components and replacing them with the ideas in the heap that contain
the values for those variables.
So those that adhere as they are being executed and evaluated.
And so on, so the whole print statement and its parameter is replaced by a single location of single
idea, I should say, right here, eight four zero eight if you're like this, which is where the string
of the result message is stored.
So one more, OK, finished, so that's done so you can see that we are now coming back from the stack
into the main part of the program.
So they stack entries now only contains like 19 because we are done with the python is really done with
the execution and the variation of the function.
So let's do one more.
Actually, I'm going to go for a step over now and print up finished and we done.
So this demonstration just wanted to show you what kind of work you can do with the additional views
and features that are available here under The View menu.
Again, we're not going to be able to use these features in our micro python programming on the specific
two, but they are available, if you're interested in general purpose, desktop or C Python programming.
The debugger that we saw in action here is actually a Python project called the Bird's Eye.
So you can find project documentation for Birds Eye here, including a tutorial on how you can use it
and what else you can do with it.
I've only scratched the surface.
It's a very interesting and useful python debugger that if you're interested in doing some more complicated
Python programming, is good to know how to use that time.
OK, now, in the next couple of lectures, like to show you how to do simple micro python programming
tasks with the BBC Microgrid and the Raspberry Pi.