Like in the previous lecture, I showed you how to automatically execute a script when the writing is
pallett up.
And we did it by adding some code inside the to a program.
Of course, if you don't want that to actually happen and you want any code to be executed when there
is power up, then make sure that there's no executable code in this file.
Or you can just delete this file and recreate it later when you need it.
So I'm going to put this away from now.
And in this lecture, which is the last one for this section, I want to show you a few techniques useful
when you do debugging and troubleshooting of your macro Python script.
So I've got the Blink script here, and the first thing that I've done in order to help me with troubleshooting
is to use print statements.
If you come from the Adreno world, then you are familiar with how we use print statements there to
try and figure out what is happening during the runtime, during the time that our script or our sketch
is being executed on.
And that is a similar principle here.
Again, I'm using print statements to print out in this case what is happening with this particular
object, and I'm printing out its value.
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
all gets zero and so on.
So this is telling me that the ality object is behaving as I expect it to behave.
So control it is stupid and clear.
So another thing that you can do is to read the comprehensive usually error messages that come from
Python when there is a problem.
So the Python interpreter, it's actually pretty good at providing information about what has gone wrong
with the execution of a script.
First of all, look at a couple of examples.
Let's say that we are trying to access Tapio that doesn't exist.
So it's just an honest mistake here.
It's sent that script to the two and you see a pretty clear error line for.
We tried to do something with an invalid pin.
So this is easy to solve, right?
You've got to for have a look at the pin parameter and fingers.
You know, which pins are valid for the especially to have you have a pin map nearby, then you know
that there is no two hundred eleven pin and that he probably meant 21, which is where my ID is connected
to something with things like other parameters.
In this case the pin parameter.
Let's say we only have pin in and pin out as constants for the type of pin object that we are trying
to create.
If you had a typo here, again, that would generate a fairly accurate error message saying that again
in line for you, trying to create an object of a type that doesn't exist.
Him, that doesn't exist, so you can go ahead and fix that is similarly.
Any type typically will generate a message that is accurate or you can see in this case, it says line
13, which is not very accurate.
Obviously at the end of the script, it's pointing the error at the end of the script, but the name
error is more appropriate here.
It gives you more clues to figure out what the problem may be.
So initially, we will look at line 13.
You won't find anything strange there.
You look at the rest of the error message and it will guide you to where the problem is.
So you may need to carefully assess the entire error message in to trace back until you can figure out
where the problem is.
So for things like typos typically have very good accuracy in the error messages to come back from the
interpreter.
I'm going to give you one more example.
Let's say that we have a typo in one of the methods.
So let's say that we try to insert a parameter in line 13.
Let's see what comes back then.
He did execute the program to line 11 and then it very accurately said that there is a problem here.
The function takes one positional argument, but to given actually this this function does not require
any commands.
But in a later lecture, I'm going to explain why you're getting another one here instead of zero.
But the fact is that the problem here has to do with the number of arguments that we have provided.
This function does not take any arguments and I have given one.
And therefore I'm getting into a message.
It can look at the documentation here as well if.
You're having trouble figuring out what the appropriate syntax is.
So in this case, we would go to ESP three to.
We would go to Pince and Jebril because we have imported the module from machine, and this will tell
you how to use these particular functions here, you can drill down to the documentation itself and
get more information about all this, including, let's say, the type of constants that are available
for the mode.
So I said earlier this only in Allapattah actually opened drain and out and out of introducers quite
a few there.
And having a look at the methods, you'll see that the value can be.
One or zero, if not providing a parameter, if it's empty.
And also here is on and off on the paramedics who set into one of facilities zero.
Again, no parameters.
So sometimes you may need to refer to the limitation to figure out what is going on.
All right.
So I'm going to leave it at that over the next few sections and dozens of lectures will be bumping into
problems with my scripts.
And in many cases, I'll be showing you live how I've gone about solving those issues.
But for now, just keep in mind that it's a good idea to keep print statements, especially if you are
developing a new script so that you get real time information about what is happening inside the program
as it's executing and become familiar over time with reading those traceback error messages from the
Python interpreter.
And I guarantee that every single time to be able to fix the.