Professional Documents
Culture Documents
OK?
So let's first try to just run this script
to see when it could get corrected results.
All right, and then we get this, which
are correct results, right?
So the n to the square is 9 and m to the square is 16, OK?
And so now, we try to use the debug function of PyCharm.
So the way to do that is first, you place something
called breakpoints in this gray area.
The way to place any breakpoint is just
to click each line like this, OK?
And the way to cancel our breakpoint
is just to click itself again, OK?
So now, let's try to put a breakpoint here.
And now, if we click this bug icon--
it says Debug Main--
we enter the debugging mode, OK?
What the debugging mode is just doing
is it's executing this program until this line, OK?
So it's not going to execute this line,
but it's running the program until the previous line.
OK, so here, we can see the PyCharm actually
give us this, the value of this variable,
n, where it tells us this n equals to 3, OK?
And also, PyCharm has this interesting feature
which shows up here.
It's this little calculator icon.
So it just says evaluate expression.
So what does it do is you can actually
type some simple expressions involving the variables already
have assigned values.
And you can just try to test the values of those expressions.
So for example, here, I can try to test,
what if I try to add a 1 to this n variable?
OK, so it tells me this equals to 4, OK?
So it knows n equals to 3, and now it can give me
the correct answer, OK?
And also, all these variables values
are showed up here in this variable section, OK?
OK, so let's say we want to move on to--
in this script, we try to execute another line, which
is m equals to 4.
The way to do that is to click here, is Step Over, OK?
So Step Over means you'll try to run another line
within the same script, OK?
So we can make a step over.
So now, you can see, PyCharm tells us m equals to 4,
and also, it shows up here as well.
OK?
And now, let's say we have already finished our debugging.
We just try to run the whole program through.
The way to do that is to click here,
which says Resume Program, OK?
So if we do this and we go to the Console,
and it will give us all the correct results.
OK, basically, you just resume running this program.
OK, so let's try this Debug function again.
OK, now, n equals to 3, m equals to 4, which
we go over it, which is good.
Now, we have another function here which is called to_square.
Now, maybe this function will give us some error, OK?
And if we try to go into that function,
then we can no longer do that by using Step Over.
We have to use something called Step Into, OK?
So now, if we click Step Into, it will actually
direct us to this file, OK?
To where this function is defined, OK?
And the way to jump out from this file
is to click the Step Out.
Now, we went back to here, OK?
And then you will notice, here, you have actually two icons.
One is called Step Into and one is called Step Into My Code.
So the difference is, Step Into allows
you to go to any function, not only defined in your own code
but also defined in some existing software packages, OK?
So for example, if this to_square
is a function defined in pandas, Step Into
will allow us to go to where pandas define this function,
OK?
And the Step Into My Code will not do that
but will only go into the function
you wrote in this project, say this utility script, OK?