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
€65.78
List Price:  €93.98
You save:  €28.19
£56.19
List Price:  £80.28
You save:  £24.08
CA$96.65
List Price:  CA$138.08
You save:  CA$41.42
A$109.01
List Price:  A$155.74
You save:  A$46.72
S$95.37
List Price:  S$136.25
You save:  S$40.88
HK$548.06
List Price:  HK$782.98
You save:  HK$234.91
CHF 63.79
List Price:  CHF 91.14
You save:  CHF 27.34
NOK kr768.84
List Price:  NOK kr1,098.40
You save:  NOK kr329.55
DKK kr490.83
List Price:  DKK kr701.21
You save:  DKK kr210.38
NZ$118.45
List Price:  NZ$169.22
You save:  NZ$50.77
د.إ257.03
List Price:  د.إ367.20
You save:  د.إ110.17
৳7,684.20
List Price:  ৳10,977.89
You save:  ৳3,293.69
₹5,855.32
List Price:  ₹8,365.11
You save:  ₹2,509.78
RM335.35
List Price:  RM479.10
You save:  RM143.74
₦84,069.65
List Price:  ₦120,104.65
You save:  ₦36,035
₨19,482.60
List Price:  ₨27,833.48
You save:  ₨8,350.88
฿2,577.20
List Price:  ฿3,681.88
You save:  ฿1,104.67
₺2,276
List Price:  ₺3,251.57
You save:  ₺975.56
B$370
List Price:  B$528.60
You save:  B$158.59
R1,331.99
List Price:  R1,902.92
You save:  R570.93
Лв128.63
List Price:  Лв183.76
You save:  Лв55.13
₩96,774.91
List Price:  ₩138,255.79
You save:  ₩41,480.88
₪263.45
List Price:  ₪376.37
You save:  ₪112.92
₱4,005.56
List Price:  ₱5,722.47
You save:  ₱1,716.91
¥10,822.37
List Price:  ¥15,461.20
You save:  ¥4,638.82
MX$1,188.83
List Price:  MX$1,698.40
You save:  MX$509.57
QR255.45
List Price:  QR364.94
You save:  QR109.49
P967.75
List Price:  P1,382.56
You save:  P414.81
KSh9,273.67
List Price:  KSh13,248.67
You save:  KSh3,975
E£3,415.20
List Price:  E£4,879.07
You save:  E£1,463.86
ብር3,983.99
List Price:  ብር5,691.67
You save:  ብር1,707.67
Kz58,616.62
List Price:  Kz83,741.62
You save:  Kz25,125
CLP$68,622.39
List Price:  CLP$98,036.19
You save:  CLP$29,413.80
CN¥506.62
List Price:  CN¥723.78
You save:  CN¥217.15
RD$4,136.69
List Price:  RD$5,909.81
You save:  RD$1,773.12
DA9,432.45
List Price:  DA13,475.51
You save:  DA4,043.05
FJ$159.25
List Price:  FJ$227.51
You save:  FJ$68.26
Q544.58
List Price:  Q778.01
You save:  Q233.42
GY$14,660.07
List Price:  GY$20,943.86
You save:  GY$6,283.78
ISK kr9,900.78
List Price:  ISK kr14,144.58
You save:  ISK kr4,243.80
DH712.14
List Price:  DH1,017.39
You save:  DH305.25
L1,250.72
List Price:  L1,786.82
You save:  L536.10
ден4,047.46
List Price:  ден5,782.34
You save:  ден1,734.87
MOP$564.82
List Price:  MOP$806.92
You save:  MOP$242.10
N$1,331.20
List Price:  N$1,901.80
You save:  N$570.60
C$2,577.12
List Price:  C$3,681.76
You save:  C$1,104.64
रु9,367.18
List Price:  रु13,382.26
You save:  रु4,015.08
S/261.74
List Price:  S/373.93
You save:  S/112.19
K265.15
List Price:  K378.80
You save:  K113.65
SAR262.54
List Price:  SAR375.07
You save:  SAR112.53
ZK1,755.70
List Price:  ZK2,508.25
You save:  ZK752.55
L327.30
List Price:  L467.60
You save:  L140.29
Kč1,658.88
List Price:  Kč2,369.93
You save:  Kč711.05
Ft25,827.61
List Price:  Ft36,898.16
You save:  Ft11,070.55
SEK kr766.20
List Price:  SEK kr1,094.62
You save:  SEK kr328.41
ARS$60,803.53
List Price:  ARS$86,865.91
You save:  ARS$26,062.38
Bs485.55
List Price:  Bs693.67
You save:  Bs208.12
COP$273,550.12
List Price:  COP$390,802.63
You save:  COP$117,252.51
₡35,067.63
List Price:  ₡50,098.77
You save:  ₡15,031.13
L1,728.60
List Price:  L2,469.54
You save:  L740.93
₲518,508.49
List Price:  ₲740,758.16
You save:  ₲222,249.67
$U2,722.73
List Price:  $U3,889.78
You save:  $U1,167.05
zł286.18
List Price:  zł408.85
You save:  zł122.66
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.