Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
So far so good.
Let's add the next argument, which is the Mac.
So because as you know, I'm lazy, I'm just going to do control down in here and that will duplicate
this line for me.
And now all I have to do is just change the options in here.
So the next option that I'm adding to my parser object is the option to allow the user to enter a new
Mac address.
So we're going to use dash em for the Mac or they can do a dash Dash Mac to give me the Mac.
We're going to start this under New Mac.
And in the help we're going to say new Mac address.
Okay.
Just another option.
We added it exactly the same that we added the one before and because we're calling the parser dot parse
args, we don't really need to do anything more.
If we go down and run the help again, you can see we have a new option which is dash em or dash dash
mark.
And the help message for this is it's the new Mac address that the person wants to use.
Now this is all good.
Now we're displaying the right health message.
We can accept user input using the arguments.
The only thing is we're still not able to use the values that the person enters, so we're still not
using it anywhere in the code and we don't even know how to use that.
Now let's have another look at our code.
So first, we're creating an object that can handle user input using arguments.
Then we're adding options to this object.
And finally we're using a method with this object that's called parse args, which basically allows
the object to understand what the user has entered and handle it.
It also returns the arguments and the values that the user entered to a variable.
If we actually give it a variable.
So it returns two sets of information, it returns the arguments and the values.
So for example, let's say we run python match changer dot py and we set the interface to learn zero
and we set the mark to
001122334455.
In this case, the arguments are interface and Mark and the values are one zero and 001122334455.
So that's why when we call parser dot parse args, it's going to go through everything that the user
inputs in here and it will separate it into two sets of information.
The first set is arguments, which is interface and Mark, and the second one is the values or options,
which is line zero and the Mark address in here.
So to capture these two sets of information, we have to use variables.
And to do that, we're going to do because we're using two variables in one line.
We're going to have to use two brackets and we're going to say options, arguments.
Are equal to whatever passer.
Don't pass args will return to me.
So you can think of this as a function.
It's actually a method, not a function.
And we'll talk about that in more details later on.
But what you need to understand is this method will return two sets of information, the arguments and
the options.
And to capture this, we're using two variables.
We're calling them options.
Arguments are equal to whatever this is going to return to me.
Now, keep in mind all the names I'm using here parser options, arguments.
I'm picking these names because I want to.
You can literally use x, y, z if you wanted to.
But like I said, it's good to use meaningful names because it makes programming easier and it makes
our code clearer.
So after this line, the options variable is going to contain the values.
So it's actually going to contain line zero and 001122334455.
And the arguments variable is going to contain the arguments.
So it's going to contain dash dash interface, dash, dash mark.
So by understanding this, you probably know that we're actually not going to use the arguments variable
right now because we never really use the arguments within our code.
But what is useful to us is the options here, because this is what contains the values that the user
inputs.
To access the value for the interface, which is land zero.
All we have to do is do options dot interface.
So it's whatever value that we used in the test in here.
Same goes for the Mac address.
If we want to access the value that the user set for the MAC address.
All we have to do is just do options dot new Mac.
So again, it's the value that we set and the test in here.
So you can literally replace every occurrence here of interface with options, dot interface and every
occurrence in here of new Mac with options dot new Mac.
Or to make it easier and make our code more readable, we can just do interface equals options dot interface.
And New Mac equals options dot new Mac.
And that's it.
We're done.
Now, since Interface and New Mac are already being used in here.
There is nothing else we need to do.
Now let's go and run our code.
I've already typed my commands, so we're doing Python mac changer.
We're giving it the interface, which is line zero.
We're giving it the Mac, which is this.
If we hit enter, you'll see the print statement is actually printing the right values for us.
And if we do, if config line zero, you'll see that my Mac address got reset to the MAC address that
we want here.
Now let's use the program using the shorter arguments, using the dash I and dash em.
So we can just do python mac changer dot py and we can just do dash.
I like this and let's change the mac address this time for zero and do dash m set the new Mac.
Hit Enter again.
Print statement is working fine and if we do if config at zero you'll see that the MAC address changed
to what we wanted to.
Now our program is actually pretty good.
It accepts user input using arguments.
It displays the help message if the target person wants to and the person can set a mac and an interface
through the command line and it'll execute it and change the Mac for them.
Now, in the future, we're actually going to be using more modules, more objects, more arguments.
And everything I showed you so far is going to become clearer.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.