1
00:00:01,200 --> 00:00:09,120
In this lecture, I'd like to show you some of the other capabilities of Sony in particular relating

2
00:00:09,120 --> 00:00:12,690
to debugging that a lot of people are asking about.

3
00:00:13,020 --> 00:00:19,510
I've got to say that these features are not really available for micro python programming on the episode

4
00:00:19,530 --> 00:00:26,820
of two, but they are available for general purpose, Python and for desktop version of Python.

5
00:00:27,060 --> 00:00:30,420
And I'm going to use that for examples that are coming up.

6
00:00:30,840 --> 00:00:36,030
Again, these are not features that we are going to be using later on in this course, but things that

7
00:00:36,030 --> 00:00:37,410
people do ask about.

8
00:00:37,410 --> 00:00:42,750
And I just wanted to make sure that you've got a good understanding of the Sony ID, Ed, before we

9
00:00:42,750 --> 00:00:44,500
get on with my python.

10
00:00:45,000 --> 00:00:50,070
So I have already opened up the via Ghosheh and Stack Winderlich.

11
00:00:50,070 --> 00:00:56,610
You can do that by going to view and choose the window that you want to open up the service, for example,

12
00:00:56,610 --> 00:00:58,800
the program tree that you can see down here.

13
00:00:59,460 --> 00:01:03,650
And let's have a look at your object, inspector and so on.

14
00:01:03,870 --> 00:01:10,830
I'm not going to go through all of them because then we are going outside of the scope of this course,

15
00:01:11,130 --> 00:01:13,890
which is to focus on micro python.

16
00:01:14,370 --> 00:01:20,400
And before I start with my small demonstration, I also want to point out that if you go to these Thorney

17
00:01:20,400 --> 00:01:23,190
dot org website, it's a very homepage.

18
00:01:23,530 --> 00:01:27,380
There's a demo video here which I have mentioned previously.

19
00:01:27,390 --> 00:01:32,060
You should really take a look at it will give you a really good overview of those features.

20
00:01:32,070 --> 00:01:35,840
And I'm also going to touch upon in this lecture.

21
00:01:36,720 --> 00:01:43,110
OK, so I'm going to turn off the object inspector and the program that really need it.

22
00:01:43,380 --> 00:01:52,170
And I'm going to switch my targeted interpreter to the default one, because, as I said, these features

23
00:01:52,170 --> 00:01:55,350
don't work with the especially to micro python version.

24
00:01:55,930 --> 00:01:58,350
So now we are running Python three point seven point.

25
00:01:58,350 --> 00:02:03,840
And I got a little program here that just adds to numbers of code number one.

26
00:02:03,840 --> 00:02:07,810
And number two, just a couple of arbitrary random numbers.

27
00:02:07,830 --> 00:02:14,550
You can also use the input function to allow you to enter those numbers during runtime.

28
00:02:15,060 --> 00:02:17,490
But let's keep things simple then.

29
00:02:17,490 --> 00:02:19,770
I've got a calculation happening here.

30
00:02:19,770 --> 00:02:27,030
The result goes into the some variable and print out the results onto the show like this.

31
00:02:27,330 --> 00:02:36,210
And I'm using the format function to talk more about this in Section five, which is fairly detailed

32
00:02:36,210 --> 00:02:37,800
introduction to Python.

33
00:02:37,810 --> 00:02:40,610
So there were better details about what this does.

34
00:02:40,620 --> 00:02:43,930
What is important right now is what the output is.

35
00:02:43,950 --> 00:02:49,110
So you run this program and you see that the output is just the sum of the calculation with a bit of

36
00:02:49,110 --> 00:02:53,570
information about what was calculated by the component of the calculation.

37
00:02:54,180 --> 00:03:00,330
Now, see what happened as soon as they executed the program is that the variables tab became populated

38
00:03:00,600 --> 00:03:06,150
with the numbers you can see here that have got the value idea, which is this is a memory location

39
00:03:06,150 --> 00:03:07,980
where no one is stored.

40
00:03:08,520 --> 00:03:12,120
And number two, and some also have the heap.

41
00:03:12,120 --> 00:03:23,280
Memory in the stack is empty and a hidden memory is where both he and Stack are stored in Ram Python

42
00:03:23,280 --> 00:03:27,090
in particular uses heap and stack differently.

43
00:03:27,450 --> 00:03:29,430
So it said both are part of their end.

44
00:03:29,430 --> 00:03:35,000
But in memory, Python is going to store the global variable she can see here.

45
00:03:35,010 --> 00:03:38,490
No one is a global variable and stored at this remote location.

46
00:03:39,950 --> 00:03:49,070
c.B zero, and that matches this idea here in the heap, which has this value one point five as it was

47
00:03:49,070 --> 00:03:52,780
assigned here, and line number three in the script.

48
00:03:52,790 --> 00:04:01,840
And similarly, number four line declares initializes variable number two, which you can see here.

49
00:04:01,880 --> 00:04:07,820
This is its value add in RAM, which is right here in the heap.

50
00:04:08,120 --> 00:04:12,630
Again, here is where Python stores its global variables.

51
00:04:13,820 --> 00:04:21,560
You've got some which was created later and its content are the result of the addition between number

52
00:04:21,560 --> 00:04:22,340
one and number two.

53
00:04:22,850 --> 00:04:26,880
We don't have anything in the stack because we don't have any functions.

54
00:04:27,500 --> 00:04:31,920
So let me show you an alternative of this little simple program.

55
00:04:32,290 --> 00:04:40,190
So here I've got the exact same thing happening, but now I've got a function declared called add numbers.

56
00:04:40,190 --> 00:04:42,110
And again, don't worry about the details.

57
00:04:42,110 --> 00:04:48,380
I'm going to talk about how to create functions in Section five of this course.

58
00:04:48,800 --> 00:04:51,890
But you'll see that we've got the global variables.

59
00:04:52,290 --> 00:04:57,490
We've got some variable created here, and then we've got a call to the function at numbers.

60
00:04:57,490 --> 00:05:03,260
So essentially the program jumps from here to here and then we're going to line number five and execute

61
00:05:03,260 --> 00:05:03,420
it.

62
00:05:03,980 --> 00:05:06,290
Now, if I run this program, see what happens.

63
00:05:07,280 --> 00:05:12,200
So after the execution of the program, one thing that we didn't really see was what happened in this

64
00:05:12,200 --> 00:05:13,360
attack, if at all.

65
00:05:13,670 --> 00:05:19,430
So this attack, as I said earlier, is where Python keeps track of its position in the program.

66
00:05:19,440 --> 00:05:25,820
Trees are especially useful when we have to go from one part of the program and continue with the execution

67
00:05:25,820 --> 00:05:27,830
of the program inside a function.

68
00:05:28,520 --> 00:05:35,780
So for Python to know where to return once the execution of the function is complete, it needs to keep

69
00:05:35,780 --> 00:05:42,740
track of the origin of the call inside the stack and to be able to see the start getting populated.

70
00:05:42,770 --> 00:05:46,350
I'm going to use the debug function first.

71
00:05:46,370 --> 00:05:50,420
I'm going to have a little line stop here.

72
00:05:50,420 --> 00:05:56,480
Just double click on the line where I want the execution to stop temporarily and then I'm going to click

73
00:05:56,480 --> 00:06:01,850
on the current screw button and that will start executing the program.

74
00:06:01,860 --> 00:06:08,360
But they will stop at the location where I've got the red dot, the stop line, and you can see that

75
00:06:08,360 --> 00:06:10,970
I've got my variables here, the global variables.

76
00:06:10,980 --> 00:06:14,000
I've got my head exactly as we did earlier.

77
00:06:14,540 --> 00:06:17,060
Now we've got an additional component in the heap.

78
00:06:17,060 --> 00:06:19,280
We've got the function ID numbers.

79
00:06:20,780 --> 00:06:22,460
So the program does know about it.

80
00:06:22,940 --> 00:06:27,380
And I can continue the execution of the program by using one of those patterns here.

81
00:06:27,890 --> 00:06:37,070
So step over, step into and step out, step over allows me to move on to the next line of the program

82
00:06:37,070 --> 00:06:46,040
without actually drilling in into the individual components that make up this line of code instead of

83
00:06:46,040 --> 00:06:47,350
going stepping over.

84
00:06:47,360 --> 00:06:53,450
I'm going to go step into to explain more about what I'm talking about here, to remember that we are

85
00:06:53,450 --> 00:06:55,280
now executing line 15.

86
00:06:55,280 --> 00:07:01,940
And I'm going to step in to and you can see that now with step into the execution continues into the

87
00:07:01,940 --> 00:07:03,650
right side of the equals sign.

88
00:07:04,720 --> 00:07:12,970
And if I click on Step into again, it drops further into the first component of this edition.

89
00:07:14,300 --> 00:07:21,950
And it will evaluate that you can see that it will change it into its I.D., so Vago no one now has

90
00:07:21,950 --> 00:07:29,780
been replaced in the code itself with its value I.D., which you can see the variables tab.

91
00:07:30,140 --> 00:07:34,610
And also in the caps, you can see it's actually assigned value.

92
00:07:35,300 --> 00:07:40,610
Do one more step in two and then it goes over to the other side and have a look at the number.

93
00:07:40,610 --> 00:07:46,670
And again, you can guess if I click on it again, it's going to into the number and replace it with

94
00:07:46,670 --> 00:07:47,330
its eyeteeth.

95
00:07:47,540 --> 00:07:53,500
But instead I'm going to go and do a step over and that is going to skip it and start exiting.

96
00:07:53,990 --> 00:08:02,690
And until eventually the whole thing, the sum of these two numbers is replaced by the idea where those

97
00:08:02,690 --> 00:08:07,460
numbers are stored, which is B three zero seven point eight.

98
00:08:08,090 --> 00:08:11,810
And it's just about again, it's going to jump into line nineteen.

99
00:08:11,840 --> 00:08:13,130
Now, look what happens here.

100
00:08:13,490 --> 00:08:18,800
As soon as I went into line 19, what is the call to the add numbers function?

101
00:08:19,160 --> 00:08:20,930
The stack keeps track of that.

102
00:08:21,260 --> 00:08:27,020
The stack now keeps track of where I'm going to jump into another part of the program, which happens

103
00:08:27,020 --> 00:08:33,350
to be a function so that this is where I'm going to return or the problem is going to return to once

104
00:08:33,380 --> 00:08:38,760
the function execution is complete and it's going to step over there and be finished.

105
00:08:38,780 --> 00:08:43,640
So it's not going to go into the function because I did a step over when to do one more thing here.

106
00:08:43,940 --> 00:08:48,800
And I'm going to say Trent finished

107
00:08:51,560 --> 00:08:55,010
like that and I'm going to execute again.

108
00:08:55,010 --> 00:09:02,900
And using the debugger this time, I'm going to go for that over for the first time and then I'm going

109
00:09:02,900 --> 00:09:06,050
to do step into four to do that.

110
00:09:06,050 --> 00:09:07,820
I'm going to open up the stack.

111
00:09:07,820 --> 00:09:15,740
When you can see that the module line 19 is in the first position of the stack them I'm going to step

112
00:09:15,740 --> 00:09:21,080
into now drilling into the function.

113
00:09:21,080 --> 00:09:22,280
And now this is interesting.

114
00:09:22,280 --> 00:09:28,760
You see that a new window popped up because now we have drilled into the add numbers function.

115
00:09:28,760 --> 00:09:32,910
So a new window popped up to show us what is happening inside that function.

116
00:09:32,910 --> 00:09:37,280
And you can see there are another entry has been made into the stack.

117
00:09:37,860 --> 00:09:45,200
This is now line five, which is the line that we are executing right now so as to step into again,

118
00:09:45,620 --> 00:09:54,230
see drilling into the individual components and replacing them with the ideas in the heap that contain

119
00:09:54,710 --> 00:09:56,810
the values for those variables.

120
00:09:56,950 --> 00:10:01,160
So those that adhere as they are being executed and evaluated.

121
00:10:03,030 --> 00:10:11,610
And so on, so the whole print statement and its parameter is replaced by a single location of single

122
00:10:11,610 --> 00:10:19,140
idea, I should say, right here, eight four zero eight if you're like this, which is where the string

123
00:10:19,140 --> 00:10:21,300
of the result message is stored.

124
00:10:23,410 --> 00:10:30,430
So one more, OK, finished, so that's done so you can see that we are now coming back from the stack

125
00:10:30,610 --> 00:10:32,220
into the main part of the program.

126
00:10:32,230 --> 00:10:41,050
So they stack entries now only contains like 19 because we are done with the python is really done with

127
00:10:41,050 --> 00:10:43,790
the execution and the variation of the function.

128
00:10:44,290 --> 00:10:45,730
So let's do one more.

129
00:10:46,910 --> 00:10:53,360
Actually, I'm going to go for a step over now and print up finished and we done.

130
00:10:54,430 --> 00:11:01,240
So this demonstration just wanted to show you what kind of work you can do with the additional views

131
00:11:01,240 --> 00:11:04,300
and features that are available here under The View menu.

132
00:11:04,720 --> 00:11:10,690
Again, we're not going to be able to use these features in our micro python programming on the specific

133
00:11:10,690 --> 00:11:18,100
two, but they are available, if you're interested in general purpose, desktop or C Python programming.

134
00:11:18,640 --> 00:11:26,550
The debugger that we saw in action here is actually a Python project called the Bird's Eye.

135
00:11:27,010 --> 00:11:35,020
So you can find project documentation for Birds Eye here, including a tutorial on how you can use it

136
00:11:35,020 --> 00:11:37,010
and what else you can do with it.

137
00:11:37,090 --> 00:11:39,480
I've only scratched the surface.

138
00:11:39,820 --> 00:11:47,470
It's a very interesting and useful python debugger that if you're interested in doing some more complicated

139
00:11:47,470 --> 00:11:50,400
Python programming, is good to know how to use that time.

140
00:11:51,350 --> 00:11:58,630
OK, now, in the next couple of lectures, like to show you how to do simple micro python programming

141
00:11:58,630 --> 00:12:04,210
tasks with the BBC Microgrid and the Raspberry Pi.
