All language subtitles for 009 Initialising Variables Based on Command-line Arguments_en

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranรฎ)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu

Original subtitles

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.