Building CLI Tools with Sys.Argv (Argument Vector)

Building Command Line Tools with Python, Julia and Nodejs Module 01 - Building Command Line Tools
13 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$69.99
List Price:  $99.99
You save:  $30
€67.35
List Price:  €96.21
You save:  €28.86
£55.83
List Price:  £79.77
You save:  £23.93
CA$100.76
List Price:  CA$143.95
You save:  CA$43.19
A$112.23
List Price:  A$160.33
You save:  A$48.10
S$95.14
List Price:  S$135.93
You save:  S$40.78
HK$543.62
List Price:  HK$776.63
You save:  HK$233.01
CHF 63.04
List Price:  CHF 90.06
You save:  CHF 27.02
NOK kr797.48
List Price:  NOK kr1,139.30
You save:  NOK kr341.82
DKK kr502.49
List Price:  DKK kr717.87
You save:  DKK kr215.38
NZ$124.10
List Price:  NZ$177.29
You save:  NZ$53.19
د.إ257.07
List Price:  د.إ367.26
You save:  د.إ110.18
৳8,361.55
List Price:  ৳11,945.58
You save:  ৳3,584.03
₹5,962.79
List Price:  ₹8,518.63
You save:  ₹2,555.84
RM314.04
List Price:  RM448.65
You save:  RM134.61
₦108,335.42
List Price:  ₦154,771.52
You save:  ₦46,436.10
₨19,495.71
List Price:  ₨27,852.21
You save:  ₨8,356.49
฿2,390.81
List Price:  ฿3,415.60
You save:  ฿1,024.78
₺2,467.44
List Price:  ₺3,525.07
You save:  ₺1,057.62
B$434.14
List Price:  B$620.23
You save:  B$186.09
R1,296.68
List Price:  R1,852.48
You save:  R555.80
Лв131.68
List Price:  Лв188.12
You save:  Лв56.44
₩102,198.93
List Price:  ₩146,004.73
You save:  ₩43,805.79
₪256.56
List Price:  ₪366.53
You save:  ₪109.97
₱4,090.81
List Price:  ₱5,844.26
You save:  ₱1,753.45
¥10,994.99
List Price:  ¥15,707.80
You save:  ¥4,712.81
MX$1,408.98
List Price:  MX$2,012.91
You save:  MX$603.93
QR255.09
List Price:  QR364.43
You save:  QR109.34
P967.82
List Price:  P1,382.66
You save:  P414.84
KSh9,046.20
List Price:  KSh12,923.70
You save:  KSh3,877.50
E£3,562.49
List Price:  E£5,089.49
You save:  E£1,527
ብር8,907.19
List Price:  ብር12,725.10
You save:  ብር3,817.91
Kz63,830.88
List Price:  Kz91,190.88
You save:  Kz27,360
CLP$69,323.69
List Price:  CLP$99,038.09
You save:  CLP$29,714.40
CN¥510.80
List Price:  CN¥729.75
You save:  CN¥218.94
RD$4,245.36
List Price:  RD$6,065.06
You save:  RD$1,819.70
DA9,465.07
List Price:  DA13,522.10
You save:  DA4,057.03
FJ$162.39
List Price:  FJ$232
You save:  FJ$69.60
Q539.11
List Price:  Q770.19
You save:  Q231.08
GY$14,638.77
List Price:  GY$20,913.42
You save:  GY$6,274.65
ISK kr9,772.70
List Price:  ISK kr13,961.60
You save:  ISK kr4,188.90
DH703.98
List Price:  DH1,005.73
You save:  DH301.75
L1,291.33
List Price:  L1,844.84
You save:  L553.50
ден4,143.97
List Price:  ден5,920.21
You save:  ден1,776.24
MOP$559.97
List Price:  MOP$800
You save:  MOP$240.02
N$1,289.45
List Price:  N$1,842.15
You save:  N$552.70
C$2,574.80
List Price:  C$3,678.44
You save:  C$1,103.64
रु9,534.71
List Price:  रु13,621.60
You save:  रु4,086.89
S/260.99
List Price:  S/372.86
You save:  S/111.86
K283.85
List Price:  K405.52
You save:  K121.66
SAR262.91
List Price:  SAR375.60
You save:  SAR112.69
ZK1,936.45
List Price:  ZK2,766.47
You save:  ZK830.02
L335.12
List Price:  L478.77
You save:  L143.64
Kč1,694.03
List Price:  Kč2,420.15
You save:  Kč726.12
Ft27,771.44
List Price:  Ft39,675.18
You save:  Ft11,903.74
SEK kr774.38
List Price:  SEK kr1,106.30
You save:  SEK kr331.92
ARS$71,792.58
List Price:  ARS$102,565.23
You save:  ARS$30,772.64
Bs484.55
List Price:  Bs692.24
You save:  Bs207.69
COP$307,165.41
List Price:  COP$438,826.54
You save:  COP$131,661.12
₡35,530.54
List Price:  ₡50,760.09
You save:  ₡15,229.55
L1,777.33
List Price:  L2,539.15
You save:  L761.82
₲546,250
List Price:  ₲780,390.60
You save:  ₲234,140.59
$U3,115.91
List Price:  $U4,451.49
You save:  $U1,335.58
zł287.82
List Price:  zł411.19
You save:  zł123.37
Already have an account? Log In

Transcript

All right, so welcome back again. So in this particular session of the course, in Module Two, we try to see how to build our own ci tools with Python. Right. So that's what we're trying to work with. So Python gives you several frameworks and several packages, that allows you to be able to build your own custom ci tools. So let's see how to work with it.

So first of all, we have to install Python to let CLG install it in case you have not installed it so far. So to install Python, you just go back to your browser and enter python.org slash download, right? So you can just download Python. So Python is a very nice programming language, which is cross platform, so you have different versions for different operating systems. So we come back to the downer session can have four windows for liners for Macintosh, and then you can just install them as you wish, right? So this is going to be an assignment for you to move on.

Now let's move on to a session on building everything from scratch. Alright, so we'll be having two different folders, we have a folder that has all the views calls day, which is referring to this particular folder that has all the videos queued up to be using in this particular course. Right? already prepared, very excited, then also have another food. And that's going to be a scratch for the beginners with nothing day, right? So this will be working now.

So let's come up to code alone, try this code. Now instead I'm going to be creating a simple file which will be run it is going to appear. Anytime that you have already decided today that you have this code file, then create a new file right? Then I'm going to save that particular file Ctrl S, let's quit assist seelye.py right, very, very interesting. So why we call it a cyst theologica in every programming language, and in most programming language, it comes with the our own package to be able to build a CLR from scratch, right without any external parties. So we'll be trying to see how to use Python itself without any external package but just this this package to be able to build it.

So I'm just going to put this so important this is CCA presents system right gives you the option of interacting with your system. right to be able to execute fashion to execute something very interesting. So what's this, I can just go with great audio synthesis can help us do. Yeah, there are three dentists who is going to go and check this particular file and bring out query response to their birthdays, we can do with this. So I'll come back to my terminal, then run, Python can use Python three, or Python two, we are using Python three, because that's what the Python version that we installed, you can also use Python two, itself. In any of them going to Python, they know the file, this is c li.

Then if I print it out, it's going to execute this particular file and give us all the peers. With this. We can do a lot of things. Because all the things we can do, we can check for the platform, we can check for Serato stuff. So let's try and see how to use this to be able to give us an information about the particular platform that you're on. So I'll comment this one out, then just go with print, then Sis, dot platform.

So in case you on Macintosh or Windows or Linus is going to give you a different information. So let's run it again. So Python says, given us a window 32. So we are on a Windows operating system. Very, very excited. Right.

So this is the name of the file. And this is Python. So Python is a program that is going to interpret whatever are written on this particular file, and give me the result. Very excited, right? So instead of me going to my home to go and check for the platform, I can just use this for my tempo and give me the same result. Very excited and very wonderful to Python, as we learned is the interpreter.

And then this is going to be the file with our instructions on it with our test, then patrons would interpret our tests and give us the result. Very excited. Now let's see how to use this seems is to be able to build a CLR so sis has another package and fJ called a dem inspector documents like the victim, right, which is called sis dot v. Today V is presented vector. So a vector is the same as a list. All right. So, with this particular option you come in to do a lot of things, as you learned in anatomy of a CLA, if you like good with CLR, then the command then your value, right.

So that is how it is. So this is going to be the CLR program, this is our Python here, then this is going to be the file itself, right. So, with this particular system, arg v, and v right is collected, all the viewers list is going to create a list in which anything I supply is going to keep it inside a particular list or vector. So, let me print this one out again. So, you can see what I need to print the list command this one out, see, if I run this the same way that we have here. See how we did.

Bye Don't go too deep. A list. So this is a list is an array. And the only name that we have there is the name of the file, right? Who is this this CSV file. Very interesting.

So it's going to be an array or a vector that is going to collect anything I'm going to type this if I type in this the Hello, because we're going to build a list with the file itself. Enough photos, right? So if I do another one for lifting a number, hello 2737 we're going to print another list right? So, the arg V is would collect a list or a vector of everything that you supply after they fall right. So by that same ID, we can be able to create a CLR because the anatomy we see a lot is that there is is anatomy, anatomy ob CLR, CLR CLR, right. You have a command.

Then you have our family. We have our CLA, an option, and then evaluate right so this is going to be the program is open to see Li is going to be a command and is going to be about two, by default is going to be one or zero. I don't count from zero, then one, then two, right. So this is going to be a list, right? So we this same idea can be used to get what's a know what quantities from a script and what a value is from a script. So let's see how to boot something like that.

So first of all, how to get the file itself, right. So to get the file, let's go with this option. Then let's go to file name, PostScript to be a file name, or the script itself, that is the run. Then to get it, I'm just going to go with sis arg v. Right? And this is zero, right? There was nothing there.

So it is going to be zero items, start counting from zero there so I go with this option, and I print it back again. So now we have our list itself, which is going to the test up here. Then default is this particular script. So that mean that is there is a file. So so we have done with this particular option, right? And then that is there.

Now how do we get our command to get our command. And I mean that command is going to be from one onwards, right. So let's see how to do this with print. Let's go to our common option, right. So in our case going to be CES at V, then from one, right, if I get one, and I post, can I print it again. Now we have our basic stuff, this our vector of model is following, there's going to be the file name, and hello is going to be the Command Option.

Very, very exciting. So we see my ideology, we can be able to build a lot of CL eyes, right? If you understand this particular option. Now let's see how to build a simple CLR. With what you have done so far, so is going to save it committed out and unless both CLR commit everything out, they can hide it and use it. So let's see why we need to do this, Eli.

So one of the Wi Fi integrators Like, if I have a function like C, diff, C Hello, quit takes a leap as a parameter. Right? And then it prints out something to print out. Hello. They need to know more for my string. Right?

Because I want to actually execute this one, right? I have to do it like this, say hello. And I pass in a name like, Jesse. Right everybody like his name. So if I run it back again, the same file, going to print hello, Jesse. Very interesting, right?

But in case I want to change this particular name, I give this file to another person. And I want to present to me that if I want to give to debit, the debit I have to come to this file and change it before if you ask it to see Hello, Debbie. This is a lot of work. Right? So this internship I wanted to use over and over again without changing the Bureau's parameters and arguments. So the solution is to convert it to a CLR and with sis CLA, we can be with the system itself can be able to do that.

So let's see how to do that. So it will have executed this, we realize that our SIS zero is the file name. And then one is the command right to name the editor that follows after the command. So we can actually put a sample file from it by going with this option that be placing this one with Dennis stuff. So basically say hello. Then I'll go with this.

And then Dennis. Right, so the next value day is going to be one, right to go to one. It's quite a bit now. Unless right again. So now I'm going to go with this. Like I'm just going to print hello, Jesse just like we had here, right?

So we are using the system at V because it's collected a list, an array of vector of names as we like, if we were to take this particular name is applied here. Very interesting. So we have empty dead but what if I have two or three punches? So let's get another function. So To create another function, this flight is going to be seen, say goodbye. Hello, we're going to see the Goodbye, see by Right.

Right. See by let's make this time Goodbye. Apologies for the noise behind. So in case I want to run this particular version if I have to create another way, so that is where we have to create a command to differentiate between this say hello, and then say goodbye, right? So, we learned that zero is a foul. One is the Command Option.

So in my case, I just go back to command to command right, then this command will be sis dot arg v. Apologies for the noise, then now the command is one, right, perfect. So now moving to one. So the next this is normally going to be the parameter is what a valid is now going to be the common right. So I'll just come back to this place. Say great. Oh, come on.

Very interesting. Then I can see if my question Call to see see Hello. Then I want you to run the clo function, right to run this the Hello function and then take this to the arg v. Not one anymore, but anything that follows after one. So let's call it us to write anything I want is to save it now and I come back here. I run it. So now I can click this option.

So the name is C Hello. And I do it. JOHN. I go to write Hello. Say hello. Say hello.

Say hello, right. The reason is given us two different answers. The first one is we have two of them still working. So we have to just take this one out. I think this one out. Now let's run it again.

Now see Hello, right so it is picking this is not a comment. So you can just actually make it like this to come on. Another candidate again, is trying to get to the commander's see. Hello, john. Hello, john Wright is able to execute it very, very interesting. Very, very excited.

So now can you apply for different commands, let's try it on a different command again, we'll be using LC command is equal to say goodbye. Say goodbye. We'll see by, right then I want to execute a see by passing this test argument value vector, then to see with now, now we have two different stuff, super anything it is john, if it can also run c by two. JOHN, then it's going to print out both of us. So the command is C by him. Goodbye, john.

Very, very interesting. So that is how to boot a simple CLR. You didn't see this, but this is very, it's a lot of work right? So we have to calculate it. length of the vector and then do all of this calculation. So that's why there are other tools we can use to build our CL eyes apart from this to see in the next session on how to use these tools to board up

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.