WEBVTT

00:01.240 --> 00:01.640
Okay.

00:01.640 --> 00:03.480
Right here in the define.

00:03.680 --> 00:06.600
In the define the function of report.

00:06.600 --> 00:08.360
You see we are printing the log.

00:08.640 --> 00:12.960
Now instead of printing these log right here.

00:13.000 --> 00:14.720
Now you can create a new function.

00:14.720 --> 00:18.640
And then for example sending an email to a specific email.

00:18.640 --> 00:20.720
And then you can call it right here.

00:20.720 --> 00:26.680
So it will send this thing instead of printing your email okay.

00:26.680 --> 00:28.200
So it is how it is working.

00:28.720 --> 00:31.320
And as you see now the code is work.

00:31.360 --> 00:34.640
It looks like it is very ugly.

00:34.680 --> 00:40.880
It is better to use object oriented programming language when you are writing your code and it's uh,

00:40.920 --> 00:43.400
while it is getting more complex.

00:43.920 --> 00:50.680
So here we are going to use classes to make this looks more beautiful.

00:50.680 --> 00:52.040
You may ask, what is a class?

00:52.040 --> 00:53.680
Okay, a class is a blueprint.

00:53.920 --> 00:59.880
While we are using, we put a lot of methods inside the classes, and then we can call it in other files

01:00.400 --> 01:01.400
in this file.

01:01.400 --> 01:06.410
And that is more beautiful and that is easy to use.

01:06.450 --> 01:12.450
Okay, so here we are going to create a new class.

01:12.450 --> 01:20.170
So while creating class just like function we first use the class keyword and then give a name.

01:20.170 --> 01:27.730
So here it's going to be capital key logger okay a logger with capital key.

01:28.290 --> 01:34.970
Now I'm going to highlight everything here and then hit one tab okay.

01:35.850 --> 01:37.930
Now it looks better.

01:38.490 --> 01:46.970
And as you see here we have two two function I think okay one function that is here.

01:46.970 --> 01:50.730
And the other function which is this one which is report function.

01:50.730 --> 01:58.850
Now that I have the class here, I need to use self with each function here as argument.

01:58.890 --> 02:04.250
The first argument is going to be self keyword and also Here.

02:06.490 --> 02:12.010
And also while we are calling in this any function in this part.

02:12.050 --> 02:12.490
Okay.

02:12.850 --> 02:19.490
Any function that you're calling, you need to add the self at the beginning of the name of that.

02:19.490 --> 02:21.450
So you see we have report here.

02:21.810 --> 02:25.610
Now you need to use self dot report.

02:25.650 --> 02:26.090
Okay.

02:27.730 --> 02:29.530
Self dot report.

02:30.010 --> 02:34.810
And also as you see we have another function that is here.

02:34.930 --> 02:40.850
Here again we need to use self dot process key press.

02:43.050 --> 02:43.490
Okay.

02:44.810 --> 02:47.850
And that is good.

02:47.890 --> 02:48.450
Okay.

02:48.490 --> 02:49.970
Right now it is giving me an error.

02:50.010 --> 02:54.530
That is because it is not inside this function.

02:54.650 --> 03:00.490
So as you see right now we have this part that is starting our program.

03:00.730 --> 03:03.250
So it is better to put them into a function.

03:03.290 --> 03:03.490
Okay.

03:03.530 --> 03:04.650
Inside a function.

03:04.810 --> 03:07.460
Here I'm going to going to define a new method or function.

03:07.620 --> 03:09.620
I'm going to name it start function.

03:10.140 --> 03:12.780
So again here I need to give self.

03:15.220 --> 03:17.180
And I'm going to select this.

03:17.180 --> 03:18.300
Hit the tab.

03:18.860 --> 03:22.340
Now it looks a bit okay.

03:23.060 --> 03:26.780
And also here you see we are calling this one.

03:27.140 --> 03:37.180
So we need to use self dot report said report self.

03:38.420 --> 03:39.740
Report self.

03:39.940 --> 03:40.820
This one okay.

03:43.700 --> 03:49.420
Uh no problem.

03:49.460 --> 03:49.860
Okay.

03:50.180 --> 03:57.980
Now that everything looks good.

03:58.180 --> 04:02.500
Uh huh.

04:02.980 --> 04:05.460
Self is not defined by list.

04:06.740 --> 04:07.020
Okay.

04:07.100 --> 04:08.260
That is because of this.

04:10.420 --> 04:13.260
So okay, now the error is gone.

04:13.780 --> 04:15.940
Now you see we have this one.

04:15.980 --> 04:16.300
Okay.

04:16.340 --> 04:18.820
That is, uh, completed.

04:18.860 --> 04:26.820
Now, if I execute, if I run this program, it will do nothing because we never called these, uh,

04:26.860 --> 04:27.540
functions.

04:27.540 --> 04:31.660
And also, we never created an object for this key logger.

04:31.700 --> 04:38.980
Okay, now, if I save this and then go back here, control C, this.

04:45.060 --> 04:46.380
Lets us clear.

04:51.020 --> 04:51.660
See?

04:51.660 --> 04:53.740
We have nothing immediately.

04:53.740 --> 04:56.100
It's, uh, closing that.

04:56.860 --> 05:03.020
So, uh, again here, inside this folder, I'm going to create a new file.

05:03.020 --> 05:07.620
I'm going to name it n logger dot p y.

05:07.660 --> 05:08.100
Okay.

05:09.110 --> 05:10.910
so we have it here.

05:10.950 --> 05:11.310
Okay.

05:12.430 --> 05:15.750
Now I'm going to import the module.

05:15.790 --> 05:16.110
Okay.

05:16.590 --> 05:18.430
It was Ilogger.

05:18.470 --> 05:21.230
Import Ilogger.

05:21.630 --> 05:24.470
And let's create an object.

05:24.510 --> 05:26.470
This is going to be my key logger.

05:27.630 --> 05:31.710
That's equal to we had a class.

05:31.710 --> 05:34.470
The class name was key logger.

05:34.510 --> 05:34.910
Okay.

05:38.910 --> 05:39.830
Not really.

05:39.830 --> 05:42.230
That key logger.

05:42.230 --> 05:46.430
Dot capital key logger.

05:46.470 --> 05:51.550
Okay, let me show you that right here.

05:51.590 --> 05:52.030
Okay.

05:52.550 --> 05:54.990
We have this class with Capital key.

05:55.230 --> 05:59.470
Every time you're importing a you're creating a class.

05:59.470 --> 06:02.830
You need to use capital letter okay.

06:02.870 --> 06:05.470
In the beginning you need to use capital letter.

06:05.870 --> 06:11.470
For example here we have let's see if we have any.

06:11.510 --> 06:12.550
Um, okay.

06:12.590 --> 06:12.950
Here.

06:12.950 --> 06:15.390
You see, we have the timer.

06:15.870 --> 06:18.470
So this timer, the T is capital.

06:18.470 --> 06:20.990
That means this timer is a class.

06:21.030 --> 06:21.430
Okay.

06:22.790 --> 06:23.870
So here the same.

06:24.350 --> 06:25.910
We are importing the key logger.

06:25.950 --> 06:27.310
We're using the key logger.

06:27.310 --> 06:28.590
Dot key logger.

06:28.790 --> 06:29.510
Okay.

06:29.550 --> 06:31.990
So this key logger is a class right now.

06:31.990 --> 06:34.750
And this is its object okay.

06:34.790 --> 06:37.550
We created the object for the key logger.

06:37.590 --> 06:43.550
Now now we have a function called start okay.

06:43.590 --> 06:45.510
So let's use that.

06:50.070 --> 06:50.830
Okay.

06:50.870 --> 06:58.430
My key logger dot start which is a function that is located here okay.

06:58.950 --> 07:04.710
Now whenever you call this function so it will start executing all the program okay.

07:05.430 --> 07:07.230
Now let me save it.

07:07.230 --> 07:12.560
And I'm going to go back here I'm going to use Python.

07:12.720 --> 07:17.640
It was in logarithm pi while I'm executing this.

07:17.680 --> 07:25.800
It is giving me an error and saying that log is not defined in which line.

07:26.480 --> 07:27.400
Line four.

07:27.440 --> 07:28.600
Line 25.

07:28.640 --> 07:28.880
In.

07:28.880 --> 07:29.240
Start.

07:29.280 --> 07:31.120
Line 25 in start.

07:31.160 --> 07:31.560
Okay.

07:34.960 --> 07:36.800
And start.

07:36.800 --> 07:37.520
Function.

07:37.520 --> 07:38.400
Line 24.

07:40.920 --> 07:41.200
Okay.

07:41.200 --> 07:42.400
We don't have it here.

07:43.920 --> 07:45.440
End log.

07:45.480 --> 07:46.080
Okay.

07:53.240 --> 07:53.560
Okay.

07:53.560 --> 07:57.200
There is one problem, and that is here.

07:57.240 --> 07:57.560
Okay.

07:57.600 --> 08:02.520
We put the log global variable inside the class.

08:03.240 --> 08:05.000
This needs to be out of the class.

08:05.040 --> 08:05.680
Okay.

08:05.720 --> 08:08.880
So for that because of that it gives me a name error.

08:08.920 --> 08:11.760
Like this log is not defined in this location.

08:12.400 --> 08:14.720
And also all other places.

08:15.120 --> 08:21.680
So now if I execute, if I add this okay, from here and put it out of the class.

08:26.800 --> 08:32.960
And let me something like this and I save this, let's come back here.

08:35.560 --> 08:37.720
Now if I type here, for example.

08:37.760 --> 08:39.480
Hello world.

08:41.480 --> 08:44.320
Now you see that it is giving me what I want.

08:44.360 --> 08:50.680
Okay, after each six second, this will give me the report.

08:50.720 --> 08:51.360
Okay.

08:51.400 --> 08:58.680
So it is how you use object oriented programming with Python and there is no big changes.

08:58.720 --> 08:59.160
Okay.

08:59.200 --> 09:04.280
It's the same thing while we were using that before.

09:04.320 --> 09:04.720
Okay.

09:06.160 --> 09:14.720
So since it's so simple, let's go and do something like this part or something.
