1
00:00:00,630 --> 00:00:09,060
Like in the previous lecture, I showed you how to automatically execute a script when the writing is

2
00:00:09,060 --> 00:00:09,810
pallett up.

3
00:00:10,200 --> 00:00:14,560
And we did it by adding some code inside the to a program.

4
00:00:14,970 --> 00:00:20,400
Of course, if you don't want that to actually happen and you want any code to be executed when there

5
00:00:20,400 --> 00:00:25,340
is power up, then make sure that there's no executable code in this file.

6
00:00:25,350 --> 00:00:29,200
Or you can just delete this file and recreate it later when you need it.

7
00:00:30,150 --> 00:00:31,800
So I'm going to put this away from now.

8
00:00:31,980 --> 00:00:37,830
And in this lecture, which is the last one for this section, I want to show you a few techniques useful

9
00:00:37,830 --> 00:00:42,420
when you do debugging and troubleshooting of your macro Python script.

10
00:00:43,020 --> 00:00:50,640
So I've got the Blink script here, and the first thing that I've done in order to help me with troubleshooting

11
00:00:50,640 --> 00:00:52,380
is to use print statements.

12
00:00:52,560 --> 00:01:01,110
If you come from the Adreno world, then you are familiar with how we use print statements there to

13
00:01:01,230 --> 00:01:07,950
try and figure out what is happening during the runtime, during the time that our script or our sketch

14
00:01:07,950 --> 00:01:09,390
is being executed on.

15
00:01:09,390 --> 00:01:11,810
And that is a similar principle here.

16
00:01:12,030 --> 00:01:16,950
Again, I'm using print statements to print out in this case what is happening with this particular

17
00:01:17,580 --> 00:01:19,700
object, and I'm printing out its value.

18
00:01:20,190 --> 00:01:27,090
So when I run the current script, you can see that here it is on then I get no one for value when it's

19
00:01:27,090 --> 00:01:28,440
all gets zero and so on.

20
00:01:28,470 --> 00:01:34,270
So this is telling me that the ality object is behaving as I expect it to behave.

21
00:01:34,860 --> 00:01:37,390
So control it is stupid and clear.

22
00:01:38,070 --> 00:01:44,490
So another thing that you can do is to read the comprehensive usually error messages that come from

23
00:01:44,490 --> 00:01:46,810
Python when there is a problem.

24
00:01:46,830 --> 00:01:53,370
So the Python interpreter, it's actually pretty good at providing information about what has gone wrong

25
00:01:53,370 --> 00:01:54,980
with the execution of a script.

26
00:01:55,560 --> 00:01:57,480
First of all, look at a couple of examples.

27
00:01:57,900 --> 00:02:03,090
Let's say that we are trying to access Tapio that doesn't exist.

28
00:02:03,090 --> 00:02:04,910
So it's just an honest mistake here.

29
00:02:05,370 --> 00:02:11,850
It's sent that script to the two and you see a pretty clear error line for.

30
00:02:13,120 --> 00:02:15,400
We tried to do something with an invalid pin.

31
00:02:16,060 --> 00:02:18,270
So this is easy to solve, right?

32
00:02:18,280 --> 00:02:23,610
You've got to for have a look at the pin parameter and fingers.

33
00:02:23,620 --> 00:02:31,900
You know, which pins are valid for the especially to have you have a pin map nearby, then you know

34
00:02:31,900 --> 00:02:38,410
that there is no two hundred eleven pin and that he probably meant 21, which is where my ID is connected

35
00:02:38,410 --> 00:02:41,040
to something with things like other parameters.

36
00:02:41,050 --> 00:02:42,820
In this case the pin parameter.

37
00:02:42,820 --> 00:02:52,030
Let's say we only have pin in and pin out as constants for the type of pin object that we are trying

38
00:02:52,030 --> 00:02:52,680
to create.

39
00:02:52,690 --> 00:03:01,960
If you had a typo here, again, that would generate a fairly accurate error message saying that again

40
00:03:01,960 --> 00:03:07,120
in line for you, trying to create an object of a type that doesn't exist.

41
00:03:09,070 --> 00:03:13,960
Him, that doesn't exist, so you can go ahead and fix that is similarly.

42
00:03:15,840 --> 00:03:23,790
Any type typically will generate a message that is accurate or you can see in this case, it says line

43
00:03:23,790 --> 00:03:26,730
13, which is not very accurate.

44
00:03:26,730 --> 00:03:33,600
Obviously at the end of the script, it's pointing the error at the end of the script, but the name

45
00:03:33,600 --> 00:03:35,820
error is more appropriate here.

46
00:03:35,830 --> 00:03:38,590
It gives you more clues to figure out what the problem may be.

47
00:03:38,610 --> 00:03:41,000
So initially, we will look at line 13.

48
00:03:41,520 --> 00:03:43,550
You won't find anything strange there.

49
00:03:43,710 --> 00:03:50,820
You look at the rest of the error message and it will guide you to where the problem is.

50
00:03:51,330 --> 00:04:00,960
So you may need to carefully assess the entire error message in to trace back until you can figure out

51
00:04:01,290 --> 00:04:02,250
where the problem is.

52
00:04:02,280 --> 00:04:09,600
So for things like typos typically have very good accuracy in the error messages to come back from the

53
00:04:09,600 --> 00:04:10,370
interpreter.

54
00:04:10,900 --> 00:04:12,390
I'm going to give you one more example.

55
00:04:12,390 --> 00:04:18,050
Let's say that we have a typo in one of the methods.

56
00:04:18,070 --> 00:04:22,230
So let's say that we try to insert a parameter in line 13.

57
00:04:22,470 --> 00:04:23,790
Let's see what comes back then.

58
00:04:25,050 --> 00:04:32,320
He did execute the program to line 11 and then it very accurately said that there is a problem here.

59
00:04:32,940 --> 00:04:39,960
The function takes one positional argument, but to given actually this this function does not require

60
00:04:39,960 --> 00:04:41,400
any commands.

61
00:04:41,400 --> 00:04:48,000
But in a later lecture, I'm going to explain why you're getting another one here instead of zero.

62
00:04:48,510 --> 00:04:54,630
But the fact is that the problem here has to do with the number of arguments that we have provided.

63
00:04:54,990 --> 00:04:58,830
This function does not take any arguments and I have given one.

64
00:04:58,830 --> 00:05:01,200
And therefore I'm getting into a message.

65
00:05:01,680 --> 00:05:05,490
It can look at the documentation here as well if.

66
00:05:06,880 --> 00:05:12,170
You're having trouble figuring out what the appropriate syntax is.

67
00:05:12,700 --> 00:05:16,780
So in this case, we would go to ESP three to.

68
00:05:19,090 --> 00:05:28,300
We would go to Pince and Jebril because we have imported the module from machine, and this will tell

69
00:05:28,300 --> 00:05:35,230
you how to use these particular functions here, you can drill down to the documentation itself and

70
00:05:35,230 --> 00:05:42,760
get more information about all this, including, let's say, the type of constants that are available

71
00:05:43,120 --> 00:05:43,890
for the mode.

72
00:05:44,500 --> 00:05:49,900
So I said earlier this only in Allapattah actually opened drain and out and out of introducers quite

73
00:05:49,900 --> 00:05:50,470
a few there.

74
00:05:51,100 --> 00:05:57,550
And having a look at the methods, you'll see that the value can be.

75
00:05:59,090 --> 00:06:05,060
One or zero, if not providing a parameter, if it's empty.

76
00:06:08,240 --> 00:06:15,800
And also here is on and off on the paramedics who set into one of facilities zero.

77
00:06:15,860 --> 00:06:17,050
Again, no parameters.

78
00:06:17,570 --> 00:06:22,790
So sometimes you may need to refer to the limitation to figure out what is going on.

79
00:06:23,960 --> 00:06:24,400
All right.

80
00:06:24,410 --> 00:06:32,570
So I'm going to leave it at that over the next few sections and dozens of lectures will be bumping into

81
00:06:32,570 --> 00:06:33,920
problems with my scripts.

82
00:06:34,460 --> 00:06:40,430
And in many cases, I'll be showing you live how I've gone about solving those issues.

83
00:06:40,440 --> 00:06:46,130
But for now, just keep in mind that it's a good idea to keep print statements, especially if you are

84
00:06:46,130 --> 00:06:53,120
developing a new script so that you get real time information about what is happening inside the program

85
00:06:53,120 --> 00:07:01,610
as it's executing and become familiar over time with reading those traceback error messages from the

86
00:07:01,610 --> 00:07:02,870
Python interpreter.

87
00:07:03,320 --> 00:07:06,230
And I guarantee that every single time to be able to fix the.
