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

af Afrikaans
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bn Bengali
bs Bosnian
bg Bulgarian
ca Catalan
ceb Cebuano
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
tl Filipino
fi Finnish
fr French
fy Frisian
gl Galician
ka Georgian
de German
el Greek
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
km Khmer
ko Korean
ku Kurdish (Kurmanji)
ky Kyrgyz
lo Lao
la Latin
lv Latvian
lt Lithuanian
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mn Mongolian
my Myanmar (Burmese)
ne Nepali
no Norwegian
ps Pashto
fa Persian Download
pl Polish
pt Portuguese
pa Punjabi
ro Romanian
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
st Sesotho
sn Shona
sd Sindhi
si Sinhala
sk Slovak
sl Slovenian
so Somali
es Spanish
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
te Telugu
th Thai
tr Turkish
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
or Odia (Oriya)
rw Kinyarwanda
tk Turkmen
tt Tatar
ug Uyghur
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 1 00:00:00,670 --> 00:00:02,290 So far so good. 2 00:00:02,469 --> 00:00:05,920 Let's add the next argument, which is the Mac. 3 00:00:06,670 --> 00:00:14,290 So because as you know, I'm lazy, I'm just going to do control down in here and that will duplicate 4 00:00:14,290 --> 00:00:15,520 this line for me. 5 00:00:15,730 --> 00:00:20,140 And now all I have to do is just change the options in here. 6 00:00:20,710 --> 00:00:29,740 So the next option that I'm adding to my parser object is the option to allow the user to enter a new 7 00:00:29,740 --> 00:00:30,760 Mac address. 8 00:00:31,360 --> 00:00:40,330 So we're going to use dash em for the Mac or they can do a dash Dash Mac to give me the Mac. 9 00:00:40,690 --> 00:00:44,080 We're going to start this under New Mac. 10 00:00:45,590 --> 00:00:50,480 And in the help we're going to say new Mac address. 11 00:00:51,790 --> 00:00:52,210 Okay. 12 00:00:52,210 --> 00:00:53,320 Just another option. 13 00:00:53,320 --> 00:00:59,950 We added it exactly the same that we added the one before and because we're calling the parser dot parse 14 00:00:59,950 --> 00:01:02,530 args, we don't really need to do anything more. 15 00:01:02,650 --> 00:01:10,510 If we go down and run the help again, you can see we have a new option which is dash em or dash dash 16 00:01:10,510 --> 00:01:11,110 mark. 17 00:01:11,620 --> 00:01:17,350 And the help message for this is it's the new Mac address that the person wants to use. 18 00:01:18,190 --> 00:01:19,840 Now this is all good. 19 00:01:19,840 --> 00:01:22,420 Now we're displaying the right health message. 20 00:01:22,420 --> 00:01:26,500 We can accept user input using the arguments. 21 00:01:26,890 --> 00:01:33,490 The only thing is we're still not able to use the values that the person enters, so we're still not 22 00:01:33,490 --> 00:01:37,450 using it anywhere in the code and we don't even know how to use that. 23 00:01:37,960 --> 00:01:40,810 Now let's have another look at our code. 24 00:01:40,810 --> 00:01:47,560 So first, we're creating an object that can handle user input using arguments. 25 00:01:48,760 --> 00:01:51,610 Then we're adding options to this object. 26 00:01:51,880 --> 00:01:59,350 And finally we're using a method with this object that's called parse args, which basically allows 27 00:01:59,350 --> 00:02:04,030 the object to understand what the user has entered and handle it. 28 00:02:04,960 --> 00:02:11,940 It also returns the arguments and the values that the user entered to a variable. 29 00:02:11,950 --> 00:02:13,870 If we actually give it a variable. 30 00:02:14,260 --> 00:02:21,370 So it returns two sets of information, it returns the arguments and the values. 31 00:02:21,550 --> 00:02:30,910 So for example, let's say we run python match changer dot py and we set the interface to learn zero 32 00:02:31,660 --> 00:02:33,790 and we set the mark to 33 00:02:33,790 --> 00:02:39,930 001122334455. 34 00:02:40,300 --> 00:02:52,210 In this case, the arguments are interface and Mark and the values are one zero and 001122334455. 35 00:02:53,080 --> 00:02:58,840 So that's why when we call parser dot parse args, it's going to go through everything that the user 36 00:02:58,840 --> 00:03:05,020 inputs in here and it will separate it into two sets of information. 37 00:03:05,020 --> 00:03:12,820 The first set is arguments, which is interface and Mark, and the second one is the values or options, 38 00:03:12,820 --> 00:03:15,850 which is line zero and the Mark address in here. 39 00:03:17,290 --> 00:03:22,720 So to capture these two sets of information, we have to use variables. 40 00:03:23,110 --> 00:03:28,030 And to do that, we're going to do because we're using two variables in one line. 41 00:03:28,030 --> 00:03:35,200 We're going to have to use two brackets and we're going to say options, arguments. 42 00:03:36,670 --> 00:03:39,340 Are equal to whatever passer. 43 00:03:39,340 --> 00:03:41,710 Don't pass args will return to me. 44 00:03:42,430 --> 00:03:45,160 So you can think of this as a function. 45 00:03:45,160 --> 00:03:47,230 It's actually a method, not a function. 46 00:03:47,680 --> 00:03:50,980 And we'll talk about that in more details later on. 47 00:03:51,220 --> 00:03:58,270 But what you need to understand is this method will return two sets of information, the arguments and 48 00:03:58,270 --> 00:03:59,200 the options. 49 00:03:59,200 --> 00:04:02,260 And to capture this, we're using two variables. 50 00:04:02,260 --> 00:04:04,000 We're calling them options. 51 00:04:04,030 --> 00:04:08,470 Arguments are equal to whatever this is going to return to me. 52 00:04:09,220 --> 00:04:14,260 Now, keep in mind all the names I'm using here parser options, arguments. 53 00:04:14,260 --> 00:04:16,630 I'm picking these names because I want to. 54 00:04:16,660 --> 00:04:19,839 You can literally use x, y, z if you wanted to. 55 00:04:19,839 --> 00:04:27,430 But like I said, it's good to use meaningful names because it makes programming easier and it makes 56 00:04:27,430 --> 00:04:29,170 our code clearer. 57 00:04:29,620 --> 00:04:35,290 So after this line, the options variable is going to contain the values. 58 00:04:35,290 --> 00:04:42,340 So it's actually going to contain line zero and 001122334455. 59 00:04:43,030 --> 00:04:47,800 And the arguments variable is going to contain the arguments. 60 00:04:47,800 --> 00:04:52,120 So it's going to contain dash dash interface, dash, dash mark. 61 00:04:52,660 --> 00:04:58,390 So by understanding this, you probably know that we're actually not going to use the arguments variable 62 00:04:58,390 --> 00:05:02,380 right now because we never really use the arguments within our code. 63 00:05:03,160 --> 00:05:10,450 But what is useful to us is the options here, because this is what contains the values that the user 64 00:05:10,450 --> 00:05:11,230 inputs. 65 00:05:12,230 --> 00:05:15,530 To access the value for the interface, which is land zero. 66 00:05:15,560 --> 00:05:19,460 All we have to do is do options dot interface. 67 00:05:19,460 --> 00:05:23,330 So it's whatever value that we used in the test in here. 68 00:05:24,200 --> 00:05:26,000 Same goes for the Mac address. 69 00:05:26,000 --> 00:05:30,020 If we want to access the value that the user set for the MAC address. 70 00:05:30,050 --> 00:05:33,980 All we have to do is just do options dot new Mac. 71 00:05:33,980 --> 00:05:37,460 So again, it's the value that we set and the test in here. 72 00:05:38,300 --> 00:05:44,900 So you can literally replace every occurrence here of interface with options, dot interface and every 73 00:05:44,900 --> 00:05:49,280 occurrence in here of new Mac with options dot new Mac. 74 00:05:49,700 --> 00:05:58,730 Or to make it easier and make our code more readable, we can just do interface equals options dot interface. 75 00:06:00,550 --> 00:06:05,260 And New Mac equals options dot new Mac. 76 00:06:07,460 --> 00:06:08,230 And that's it. 77 00:06:08,240 --> 00:06:08,840 We're done. 78 00:06:09,230 --> 00:06:13,310 Now, since Interface and New Mac are already being used in here. 79 00:06:13,340 --> 00:06:15,590 There is nothing else we need to do. 80 00:06:16,370 --> 00:06:19,200 Now let's go and run our code. 81 00:06:19,220 --> 00:06:23,240 I've already typed my commands, so we're doing Python mac changer. 82 00:06:23,300 --> 00:06:25,970 We're giving it the interface, which is line zero. 83 00:06:26,000 --> 00:06:28,870 We're giving it the Mac, which is this. 84 00:06:28,880 --> 00:06:35,480 If we hit enter, you'll see the print statement is actually printing the right values for us. 85 00:06:35,870 --> 00:06:43,400 And if we do, if config line zero, you'll see that my Mac address got reset to the MAC address that 86 00:06:43,400 --> 00:06:44,360 we want here. 87 00:06:45,080 --> 00:06:51,630 Now let's use the program using the shorter arguments, using the dash I and dash em. 88 00:06:52,460 --> 00:06:58,540 So we can just do python mac changer dot py and we can just do dash. 89 00:06:58,550 --> 00:07:07,550 I like this and let's change the mac address this time for zero and do dash m set the new Mac. 90 00:07:08,850 --> 00:07:11,070 Hit Enter again. 91 00:07:11,070 --> 00:07:19,860 Print statement is working fine and if we do if config at zero you'll see that the MAC address changed 92 00:07:19,860 --> 00:07:21,420 to what we wanted to. 93 00:07:22,290 --> 00:07:24,900 Now our program is actually pretty good. 94 00:07:25,110 --> 00:07:28,680 It accepts user input using arguments. 95 00:07:28,710 --> 00:07:35,700 It displays the help message if the target person wants to and the person can set a mac and an interface 96 00:07:35,700 --> 00:07:40,140 through the command line and it'll execute it and change the Mac for them. 97 00:07:40,830 --> 00:07:46,860 Now, in the future, we're actually going to be using more modules, more objects, more arguments. 98 00:07:46,860 --> 00:07:50,580 And everything I showed you so far is going to become clearer. 9524

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.