ArgParse - Variadic Number of Arguments

Building Command Line Tools with Python, Julia and Nodejs Module 02 - Building Command Line Tools in Python with ArgParse
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.26
List Price:  €93.23
You save:  €27.97
£55.95
List Price:  £79.94
You save:  £23.98
CA$95.75
List Price:  CA$136.79
You save:  CA$41.04
A$107.23
List Price:  A$153.20
You save:  A$45.96
S$95.15
List Price:  S$135.94
You save:  S$40.78
HK$547.94
List Price:  HK$782.80
You save:  HK$234.86
CHF 63.91
List Price:  CHF 91.30
You save:  CHF 27.39
NOK kr766.40
List Price:  NOK kr1,094.90
You save:  NOK kr328.50
DKK kr486.75
List Price:  DKK kr695.39
You save:  DKK kr208.64
NZ$117.46
List Price:  NZ$167.81
You save:  NZ$50.35
د.إ257.06
List Price:  د.إ367.25
You save:  د.إ110.18
৳7,670.29
List Price:  ৳10,958.03
You save:  ৳3,287.74
₹5,832.01
List Price:  ₹8,331.80
You save:  ₹2,499.79
RM334.37
List Price:  RM477.70
You save:  RM143.32
₦88,678.72
List Price:  ₦126,689.32
You save:  ₦38,010.60
₨19,457.85
List Price:  ₨27,798.13
You save:  ₨8,340.27
฿2,591.43
List Price:  ฿3,702.20
You save:  ฿1,110.77
₺2,274.88
List Price:  ₺3,249.97
You save:  ₺975.09
B$360.25
List Price:  B$514.66
You save:  B$154.41
R1,330.75
List Price:  R1,901.16
You save:  R570.40
Лв127.68
List Price:  Лв182.41
You save:  Лв54.73
₩96,191.02
List Price:  ₩137,421.64
You save:  ₩41,230.61
₪265.67
List Price:  ₪379.55
You save:  ₪113.87
₱4,044.82
List Price:  ₱5,778.57
You save:  ₱1,733.74
¥10,886.62
List Price:  ¥15,552.99
You save:  ¥4,666.36
MX$1,193.70
List Price:  MX$1,705.36
You save:  MX$511.66
QR254.90
List Price:  QR364.16
You save:  QR109.26
P969.33
List Price:  P1,384.82
You save:  P415.49
KSh9,413.65
List Price:  KSh13,448.65
You save:  KSh4,035
E£3,352.26
List Price:  E£4,789.16
You save:  E£1,436.89
ብር3,973.96
List Price:  ብር5,677.33
You save:  ብር1,703.36
Kz58,616.62
List Price:  Kz83,741.62
You save:  Kz25,125
CLP$66,678.07
List Price:  CLP$95,258.47
You save:  CLP$28,580.40
CN¥507.14
List Price:  CN¥724.52
You save:  CN¥217.38
RD$4,110.44
List Price:  RD$5,872.31
You save:  RD$1,761.87
DA9,401.90
List Price:  DA13,431.87
You save:  DA4,029.96
FJ$160.42
List Price:  FJ$229.18
You save:  FJ$68.76
Q543.26
List Price:  Q776.12
You save:  Q232.86
GY$14,630.45
List Price:  GY$20,901.55
You save:  GY$6,271.09
ISK kr9,795.80
List Price:  ISK kr13,994.60
You save:  ISK kr4,198.80
DH709.23
List Price:  DH1,013.23
You save:  DH303.99
L1,246.59
List Price:  L1,780.93
You save:  L534.33
ден4,020.35
List Price:  ден5,743.61
You save:  ден1,723.25
MOP$563.94
List Price:  MOP$805.67
You save:  MOP$241.72
N$1,340.22
List Price:  N$1,914.68
You save:  N$574.46
C$2,572.43
List Price:  C$3,675.06
You save:  C$1,102.63
रु9,316.74
List Price:  रु13,310.19
You save:  रु3,993.45
S/259.29
List Price:  S/370.43
You save:  S/111.14
K265.67
List Price:  K379.55
You save:  K113.87
SAR262.50
List Price:  SAR375.02
You save:  SAR112.51
ZK1,825.88
List Price:  ZK2,608.51
You save:  ZK782.63
L324.76
List Price:  L463.96
You save:  L139.20
Kč1,644.30
List Price:  Kč2,349.11
You save:  Kč704.80
Ft25,615.12
List Price:  Ft36,594.60
You save:  Ft10,979.47
SEK kr760.35
List Price:  SEK kr1,086.27
You save:  SEK kr325.91
ARS$61,118.20
List Price:  ARS$87,315.45
You save:  ARS$26,197.25
Bs482.97
List Price:  Bs689.99
You save:  Bs207.01
COP$272,384.35
List Price:  COP$389,137.18
You save:  COP$116,752.82
₡35,055.79
List Price:  ₡50,081.85
You save:  ₡15,026.05
L1,725.31
List Price:  L2,464.83
You save:  L739.52
₲519,197.15
List Price:  ₲741,742.01
You save:  ₲222,544.85
$U2,684.12
List Price:  $U3,834.62
You save:  $U1,150.50
zł281.58
List Price:  zł402.27
You save:  zł120.69
Already have an account? Log In

Transcript

All right, so welcome back again. So in this last session, we tried to see how to work with another format of the optional argument called variadic, or variable i can make right. So let's see how to work with it in this session. I'm just going to create a new file. And I'm going to save it as arguments right before the scope of an argument. sila.

So there's going to be four Personnel Committee very, very interesting. We're still working with an argument. So this is what we did for the previous one. I said, Let's run everything from scratch. Copy this entire stuff here. Let's build everything from scratch you stick with you so from Park pass, put pasa, right, good, good.

I mean fashion is going to be our main function. We pass in our CLS stuff which is going to be a simple CLR with us, right? Everything is going to go here. So first off, we're going to create a parser. Pretty good to be used to construct or pass arguments, right? It's going to be our constructor, our initializer.

So let's get us in it. And it's all constructor. It was meant to be a pass, but admits pass. If it didn't take our program name, which is going to be our OPT right option argument. Then the next one can just give it a description. I see let alone You're going to be simple.

See Li for variable very long Celeste beautified by being at something very simple, very bit. That is the basic parts that are initialized then we need to be able to add Option argument. Then Next, I'm going to stall argument in our next piece talking on a space, then that is all so let's close it with the basic idea. Now let's see how to work with our option argument. So we learned that optional 22 Alico see the dash dash right so be trying to see how to work with variable number of arguments or variadic. argument to pass casados argument and I'll pass in the format to this is going to be I see our face may still be using it then is going to ask a very simple and very basic so let's go to help your 15 that is what I need less story written how sofa To decide x, you can call it as any but mostly we call it a two parter but pass x.

Perfect, they become prints X to get on so that is something very basic. Now let's explain what I mean by variadic. So the variadic or variable number of document gives you the option of supplying multiple names. So this is just Firstly, so it gets to keep multiple needlessly, you have two first names. So let's go with this option. So if I come back to the same thing, let's run with the help.

Let's go back to Python three then have arguments that help going to see firstly my two I want to supply multiple face names to see have to face names. So my name is Peter Paul, right? I want to pass in a scene, multiple names but with the same argument, the same option, okay, so come back to this as good as they should format. Then I can go with, let's say, john paul. Right. So I agree, john paul said I cannot recognize Paul, right.

But Paul, I'm trying to tell you that Paul is part of the family. So it I do it in this particular format. Put in a string like this, then I is going to identify that john paul are together, right? That is one way of doing it. But I don't want it to be like that, I want it to be multiples, right? So I want to tell the user that the user can also use more than two names or more than three names.

So that is where we can use variadic number of arguments. So in our case, I just want to come to this place and pass in any algae, which is going to be the number of argument that you would pick right to how many arguments to I want to supply. So if I specify that I want to supply either two by three, these are going to supply two did not supply two is going to give an arrow that is the basic idea behind this. So let's try to see a comeback to centenary did I might do to help every Chinese interested and then you can see that from hearing it as applied to this is firstly firstly rice with telling the user that you must apply to face names in a previous one without this let's go without this one and let's check campaigns with our Guru the same thing help nice only one face maybe right so this firstly 15 is referring to two different number of arguments that you can supply but without is going to keep only one.

So I can only supply multiple by default technically one I admit right by default. So let's go back it has to come back to two unless one run it again to see if I come back to this that I just go with john right and I can just do it for john and Paul is going to accept it and divided into two very very interesting a very simple so this is very, very useful gives you writing little functions. So by supplying to write if I go into one going to give us an arrow right that was my Ultimate arrow admits firstly expected to admit to it's very, very strict, right? So this is very strict. Now let's see. And I know we can analytics on this we'll do that and also create another one for this let's create another.

Let's call this one a salary. Hello, right. So this we are going to call this one and this is also your salary for this consider your salary. Let's grab it that you want, but this is supposed to be s so let's change it and let's run it again. Nope. Now we have salary and SLA Tomasello salary twice just as we did.

So, now I can come back to this place, go it is for salary and I can put in salary and then the next value, pivot so namespace name, non salary into a list, very interesting. So I can also add some other stuff. So the abuse, Radek, I can click on Apply. So the basic verdict I've made is that it's what the periodic variable I'll give it the first one that we can just go with this option, right? There's no one for this. So I have another one for terrorists, right so and then the number is you want to keep it with law number, these are the basic variadic or biological supply for the energy.

So with this option, we had only two kids I wanted to be multiple, right? To be more than one to see more than one. I'll just go with one on one. So this is going to be zero or one, right? Then this is going to be for all and at least one very interesting and then this is going to be 400 or tragedies like this Because I want to get through or I can just come back to this so we This option is called the Nana pasa argument It is something like CT if it's not just going to supply too much then less passing your city so he I can just go with any RGS then I can supply that particular option that I wanted to be so let's I want to supply multiple, at least one value right so in case I want to set supply at least one value, I'll just go with the plus.

Right. So it must be inside this. So let's run it and see what I mean by that. I need back. I do agree without it. It was to able to wake right at least one because it's at least one value.

They hope it's still showing city so the city can be zero or one right can be as many as you wish to if I come back here and let's run it again like I just come back to a city this cute as London is going to wick if I pass in London Accra something like this criminally Green Bay City anyway, see we've collected so the basic idea behind this particular option of dividing number of items is able to accept one or more right at least at least one right very, very interesting idea with a plus option. So let's check that I want to do so I'm going to come back and then let's create another one here. pasa but I'd like to meet which is going to be for something different this city let's go it occasion Let's make a job right the job title patent us today let me do multiple jobs.

So in this place to be, I hope to be job that a person does. So your chops and I can escalate any RG s, then I got specified that supposed to be one zero or one zero or one so I can give two for that. So let's come back here and then go back to the help. That is there on one jobs. If I run this one with a jobs developer that was able to work perfectly and have to go with multiple developer spiffy DevOps data scientists It was not able to recognize it right. So it is it has zero or one with this particular option.

So this is very, very strict is zero or one not more than that very interested. So I can go without it. Go riddle supply any value, and is still going to make not equal to zero or one third the basic idea behind variadic. So, you can just check these things and keep it in mind. And in case you also want to get or just go with this option, so, let's change this one to this change one of them. I just pick salary and make it wages for all of them so that you have an idea about how each and every one of them must be right.

So food, which is W four which and then you have this one's for your wage wages There's going to be in this collection of stairs, stairs is either zero or two can take as many as it. So this is going to be like multiple value is going to set multiple values to multiple variables. Right. Very, very interesting, I think as many as you wish. So let's come back to this place. So I can just carry weight is computing 1018 many values as I wish.

I set all of them so that is a part of the series 1012. Thank you for watching. In a nutshell, the basic idea that's just going to input a capacitor, then could you create your initializer or constructor, then going to add your auction argument. So doing biotic argument or grab a number of admit, just go with any args. So you can specify the number which is going to be two Specify plus, which is going to be all at least one, specify the question mark is going to be zero or one, like especially specify the asterisk which going to be zero. So thank you for watching, and see you in the next session.

Stay blessed.

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.