WEBVTT

00:00.560 --> 00:01.240
Hey, friends.

00:01.320 --> 00:02.080
Welcome back.

00:02.440 --> 00:06.360
Now let's go and change our program in a way that we can use it in a better way.

00:06.400 --> 00:11.600
Okay, now, for example, I'm going to write Python and then Mac Changer dot Pi.

00:11.640 --> 00:18.640
I want to specify the interface like dash I or dash interface, and then eta zero.

00:19.960 --> 00:24.800
And then like dash M is going to be Mac address okay.

00:26.160 --> 00:26.880
Like this.

00:27.760 --> 00:29.440
So how can I do this.

00:29.480 --> 00:31.440
It is not very easy to do it okay.

00:31.440 --> 00:37.000
Because we need to specify this that these program understand this okay.

00:37.040 --> 00:42.360
Or get this argument from here not from inside the program.

00:42.360 --> 00:49.840
So it is very easy if we use a module called Optparse or Optparse.

00:49.880 --> 00:58.440
So let's use that okay I'm going to import that is Optparse and I'm going to use it here okay.

00:59.640 --> 01:02.800
So first we need to create its object.

01:02.840 --> 01:04.680
Let's name it parser.

01:04.720 --> 01:09.000
It is equal to Opt R dot.

01:10.080 --> 01:10.880
Opt.

01:11.280 --> 01:11.720
Parse.

01:14.560 --> 01:15.480
Parser.

01:15.520 --> 01:17.960
Let's remove this and write it from the beginning.

01:18.280 --> 01:20.760
It is OP sorry.

01:20.800 --> 01:21.760
It's option.

01:24.480 --> 01:25.120
Parser.

01:25.360 --> 01:29.960
So it is a function okay not a function is a class because it is start with capital.

01:30.000 --> 01:30.760
Capital letter.

01:30.760 --> 01:32.480
Anything that is started with capital letter.

01:32.880 --> 01:33.320
Yes.

01:33.840 --> 01:42.080
Remember that is a class and it has a lot of child and a lot of like methods function that we can use

01:42.080 --> 01:42.200
it.

01:42.200 --> 01:42.760
Okay.

01:42.800 --> 01:47.480
So here we have this parser right now which is an object.

01:47.480 --> 01:52.680
It has other function like adoption like a lot of things that we can use it okay.

01:52.720 --> 01:59.880
So here let's use it I'm going to say add ops parser dot add option.

02:00.720 --> 02:05.440
Add option is a method okay that here we can use it okay.

02:05.480 --> 02:10.320
So here I'm going to give dash I y dash I that means interface.

02:10.440 --> 02:19.120
If someone gives Or provide that I and the program should understand that it is an interface or the

02:19.120 --> 02:22.240
user could enter interface.

02:22.280 --> 02:22.680
Okay.

02:23.120 --> 02:32.360
So this board is going to be this is equal to enter paste okay.

02:32.400 --> 02:41.800
If someone write I or dash interface that means it is going to be interface okay.

02:41.840 --> 02:46.760
So it will get this interface from output.

02:46.760 --> 02:53.120
And then or we can write a help here okay.

02:53.160 --> 02:54.360
Help is equal to.

02:56.480 --> 03:02.280
Help is equal to let's say interface to change it.

03:02.840 --> 03:07.880
Make it interface to change its.

03:10.600 --> 03:12.440
Mac address.

03:13.080 --> 03:14.680
Now let me save this.

03:15.080 --> 03:18.760
And here I am going to Use.

03:18.760 --> 03:19.920
Partial dot.

03:21.320 --> 03:22.120
Partial dot.

03:24.840 --> 03:25.880
Uh.

03:25.920 --> 03:26.400
Hours.

03:30.160 --> 03:30.720
Hours.

03:31.920 --> 03:32.320
Okay.

03:32.840 --> 03:34.800
Now call it.

03:35.000 --> 03:35.520
And.

03:37.720 --> 03:38.920
I'm going to execute this.

03:38.920 --> 03:39.320
Okay.

03:39.880 --> 03:41.080
Let's come right in here.

03:43.240 --> 03:43.680
Okay.

03:43.680 --> 03:44.400
We have it.

03:44.520 --> 03:45.920
So we have Mac Changer.

03:45.920 --> 03:48.200
And now let's specify Dash I.

03:48.200 --> 03:55.000
And this interface is going to be either zero okay it is zero or let's go with dash help.

03:56.520 --> 03:58.680
Dash dash help.

03:59.080 --> 04:00.320
Let's hit enter.

04:00.360 --> 04:02.640
Now you see that I have an error here.

04:02.640 --> 04:07.800
And it is say option passed object has no attribute pass args okay.

04:10.360 --> 04:16.080
And that is my problem okay.

04:16.120 --> 04:19.960
Here we have a misspelling I think okay.

04:20.000 --> 04:26.560
It is not a r g e it is a r Gee, is that was my mistake.

04:26.560 --> 04:27.200
Sorry.

04:28.720 --> 04:30.200
Let's execute this again.

04:30.200 --> 04:30.840
And here.

04:30.880 --> 04:33.320
Now you see that it gives you options.

04:33.680 --> 04:34.520
Dash h or dash?

04:34.520 --> 04:34.800
Dash.

04:34.840 --> 04:37.840
Help show this help message and exit.

04:37.880 --> 04:43.040
So see we have dash I which is equal to interface and interface.

04:43.240 --> 04:46.840
And also it says that interface to change its Mac address.

04:46.880 --> 04:47.520
Okay.

04:47.560 --> 04:52.840
And it is saying that if you use Dash I with this it will change the interface.

04:52.840 --> 04:57.520
And also the help that this text that we write okay.

04:57.560 --> 04:59.600
Interface to change its Mac address.

04:59.600 --> 05:03.000
It is the text that we just write here.

05:03.040 --> 05:03.360
Okay.

05:03.400 --> 05:04.320
Write it down here.

05:04.760 --> 05:13.920
So now you learn okay slowly that how can we get an argument from user from output.

05:13.960 --> 05:15.080
So from terminal.

05:15.120 --> 05:15.800
Okay.

05:15.840 --> 05:23.200
So now let's go and see how we can get all and everything which was interface and also new Mac address

05:23.200 --> 05:28.320
and how we can use it down here to interact.

05:28.400 --> 05:30.240
So let's go and see that.
