ArgParse - Introduction

Building Command Line Tools with Python, Julia and Nodejs Module 02 - Building Command Line Tools in Python with ArgParse
9 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.64
List Price:  €93.77
You save:  €28.13
£56.58
List Price:  £80.84
You save:  £24.25
CA$96.26
List Price:  CA$137.53
You save:  CA$41.26
A$109.08
List Price:  A$155.84
You save:  A$46.75
S$95.27
List Price:  S$136.11
You save:  S$40.83
HK$548.12
List Price:  HK$783.07
You save:  HK$234.94
CHF 63.72
List Price:  CHF 91.04
You save:  CHF 27.31
NOK kr771.14
List Price:  NOK kr1,101.67
You save:  NOK kr330.53
DKK kr490.05
List Price:  DKK kr700.10
You save:  DKK kr210.05
NZ$118.86
List Price:  NZ$169.82
You save:  NZ$50.95
د.إ257.05
List Price:  د.إ367.23
You save:  د.إ110.18
৳7,664.43
List Price:  ৳10,949.65
You save:  ৳3,285.22
₹5,835.09
List Price:  ₹8,336.20
You save:  ₹2,501.11
RM334.83
List Price:  RM478.35
You save:  RM143.52
₦90,777.03
List Price:  ₦129,687.03
You save:  ₦38,910
₨19,435.77
List Price:  ₨27,766.58
You save:  ₨8,330.81
฿2,575.67
List Price:  ฿3,679.68
You save:  ฿1,104.01
₺2,273.66
List Price:  ₺3,248.23
You save:  ₺974.56
B$364.16
List Price:  B$520.25
You save:  B$156.09
R1,350.44
List Price:  R1,929.28
You save:  R578.84
Лв128.28
List Price:  Лв183.27
You save:  Лв54.98
₩96,200.90
List Price:  ₩137,435.75
You save:  ₩41,234.85
₪263.23
List Price:  ₪376.07
You save:  ₪112.83
₱4,029.53
List Price:  ₱5,756.72
You save:  ₱1,727.18
¥10,822.20
List Price:  ¥15,460.95
You save:  ¥4,638.75
MX$1,196.86
List Price:  MX$1,709.87
You save:  MX$513.01
QR254.81
List Price:  QR364.04
You save:  QR109.22
P969.97
List Price:  P1,385.73
You save:  P415.76
KSh9,183.54
List Price:  KSh13,119.90
You save:  KSh3,936.36
E£3,382.61
List Price:  E£4,832.51
You save:  E£1,449.90
ብር3,968.10
List Price:  ብር5,668.96
You save:  ብር1,700.85
Kz58,581.63
List Price:  Kz83,691.63
You save:  Kz25,110
CLP$66,657.14
List Price:  CLP$95,228.57
You save:  CLP$28,571.42
CN¥506.67
List Price:  CN¥723.85
You save:  CN¥217.17
RD$4,155.65
List Price:  RD$5,936.90
You save:  RD$1,781.25
DA9,420.16
List Price:  DA13,457.95
You save:  DA4,037.79
FJ$159.39
List Price:  FJ$227.72
You save:  FJ$68.32
Q543.16
List Price:  Q775.98
You save:  Q232.81
GY$14,611.27
List Price:  GY$20,874.15
You save:  GY$6,262.87
ISK kr9,886.08
List Price:  ISK kr14,123.58
You save:  ISK kr4,237.50
DH707.48
List Price:  DH1,010.74
You save:  DH303.25
L1,253.52
List Price:  L1,790.82
You save:  L537.30
ден4,041.45
List Price:  ден5,773.75
You save:  ден1,732.29
MOP$563.44
List Price:  MOP$804.95
You save:  MOP$241.50
N$1,341.89
List Price:  N$1,917.07
You save:  N$575.18
C$2,586.83
List Price:  C$3,695.63
You save:  C$1,108.80
रु9,327.64
List Price:  रु13,325.78
You save:  रु3,998.13
S/260.57
List Price:  S/372.26
You save:  S/111.68
K265.99
List Price:  K380
You save:  K114.01
SAR262.56
List Price:  SAR375.10
You save:  SAR112.54
ZK1,793.08
List Price:  ZK2,561.66
You save:  ZK768.57
L326.81
List Price:  L466.89
You save:  L140.08
Kč1,658.72
List Price:  Kč2,369.71
You save:  Kč710.98
Ft25,891.40
List Price:  Ft36,989.30
You save:  Ft11,097.90
SEK kr763.84
List Price:  SEK kr1,091.25
You save:  SEK kr327.40
ARS$60,978.78
List Price:  ARS$87,116.28
You save:  ARS$26,137.50
Bs483.61
List Price:  Bs690.90
You save:  Bs207.29
COP$274,351.87
List Price:  COP$391,948.05
You save:  COP$117,596.17
₡35,072.06
List Price:  ₡50,105.09
You save:  ₡15,033.03
L1,724.15
List Price:  L2,463.18
You save:  L739.02
₲516,670.58
List Price:  ₲738,132.47
You save:  ₲221,461.88
$U2,687.21
List Price:  $U3,839.04
You save:  $U1,151.82
zł283.10
List Price:  zł404.45
You save:  zł121.34
Already have an account? Log In

Transcript

All right, so welcome back again, my name is Jesse and in this session of module to be trying to see how to work with another CNI package CO, op pass, right? So I passed a very, very nice package is going to be used to build your own CNI. Now let's see how to work with it. So what is a class? So a class simply is a simple standard library package that allows you to pass arguments and then process them, right. So it's a complete argument passing and processing library.

And then it's a replacement for OPT pass, which was also a standard library. But a pass has a lot of features added to it and is having a very nice API. So that is the big idea behind a pass. So it includes a list of tools for building command line argument, a position in the name is passed to ensure this argument, pass, right? So you just want to consume a lot of argument and then pass it and then put it so let's see how to work with a capacitor in a session. All right, we'll come back again.

I'm going to just create a CD into our model two is going to be our model two, and then we'll create a folder called path. So mkD out to the right foot path to Professor. So you're working from from a switch. So now let's see how to work with it. You don't need to install a class, it's already a standard library. So we can just go to the V in liquid liquid office file, I just come back to this place.

Now create our new file, which is going to be saved as basic saving it as basic. See ally pack, right? That is the basic idea behind it. So that's going to be what to be working on. Now let's see how to work with it. so special for decoding input.

Input had passed it in a nested I'm just going to create our main function. You can go without This mean function better is better, we actually put together a main function like, let's go to the simple see Li with a class, it's going to be a simple CLR with a pass. If it does what we need, then we are going to create classes without using it. So everything in between our main flagship, I just want to do with a recommendation as ever with overcoming it. But let's go in this particular Main Fashion approach. Okay, so let's see how to add to the face.

Now you needed to just want to create a constructor, right? So we want to be a constructor previously soon going to be used to initialize our app, right? So the first is going to be a parser. constructor is going to go with our app class, then dot argument parser. That is the basic idea. So arguments data.

So with this admin panel, you're going to consume every form of argument that is going to come and then pass the In processing, so as a basic ID, that is all. So all that you need is this particular stuff. So everything is going to go in between or be received at the admin side takes a lot of options to the argument. So one of them is attend school with the program name to pro program name right we can be whatever name we are given to us with a specific theme. So if I save this one now, that is what we need, right. So this is going to be the name that's going to be given to the program.

And also add a description to it is going to be description. For description, coming to Islam job, a pre description, write a description, a description that comes when the app is open, and also have an epilogue that this addition is after the main commands. So let's see the simple one. So let's go just a simple CLR with us. So let's position it all so that's it looks beautiful and clean. Third is something very big.

So let's run out. So that's something simple that you have made. So to be able to run this up, you have to first of all, stored the argument by an admin admin to it, but I just run it straight away from it. So let's run it and see, come back here and go to run into Python three, then our basic CLR to CD into our footer, then go with Python three, then our basic CLR go with this option to enable the Cuba native because only a pass in it without killing us any other stuff. So, to be able to see the various stuff you have to face for process, whatever the note is going to come to you can do that by going with this option of x, then go with Pass Pass Pass or the arguments that happen to that is auto renew. So with this option, we are closing it.

So first of all, we are first of all creating a passer constructor to consume every argument and process them, then we are storing every one of the argument is that this x option. Now if I come back to this place, and I run it again, the same thing I ran with the help, we are going to see some big formation. And I just have to work with Akbar. So the basic idea that you just you put a pass, then you create your parser, or constructor, right? With your program name, and then the description. Very, very interesting.

So if I come back here, you can see that now this is going to be my basic theme that is the name of the program, which is referring to this one, right, so if I change this one to something like you see basic to get rid of a question mark, and let's save it and run it again. So run it again, we're going to see the difference between the usage. So now the usage here is basically a lie, right? Without a hyphen or without a dash D. That's the basic idea behind proc write the program. So it's very, very important. So the program name is going to be the name is going to be useful to usage and then you can also see a simple CLR with a class which is paired to this Description.

Yeah, that is what I mean. So now there's another we can add another description called a pillbox with a plug is articulated to epi. Look, it looks going to be something after the main description, right? It's usually okay after the main description. So let's give it as an additional additional description. See if I see this one now you're going to see ways to tap it.

So they may description comes before the argument and then the epilogue comes after it. So let's run it again. So come back here, when the hope is that the additional description came after the argument in a command has been given, that is a busy difference between the epilogue and then the description right? So it's very, very interesting with the epilogue can actually give additional description, maybe the websites that you can find this particular COI or maybe some Moodle or something right, that is the basic idea behind a pillar. Very interesting. Now let's move on to the next session and see how to work which often argument and then other pushing argument.

So before you can also add another committee you only have a help you get I want to add another option I admit which is mostly recommended in which is to keep their budget. So how do you do that? The simplest we just go with this option that is going to be efficient, right. So, simplest we're just going to create a parser then dot add argument. So, this book argument is going to be used to be able to enable us to add different arguments. So it takes either a positional argument or an optional activity based on higher go to supplied.

Let's go with this option. Then now we're going to go with which document is going to be an optional argument as we learnt, often argument of course with dash dash, right, so don't forget that. So by default, our path is going to identify that anytime something is coming with this option. It's going to be a optionality. We also need the short form, which is going to be the long form in and this is going to be the short form it then we are going to supply the particular version in an action. So if I go with this version, and also specified so we can just use a normal formatting to be approved.

So this book is very into this program here that we have here. Right? If it Dan is going to move on to the other one. So let me 0.01 right as efficient number to keep it very interesting, then we're going to set that action to vision. That's all we need. So the actions are used to store the particular action for that particular argument.

What is that admins going to do? Is it going to store it is it going to show us a true value or boolean value as it is ladies Let's save information then this is going to be patient right? So as the name of it, it must be an attitude. This action is going to tell us They kind of asked me to do what I do to store the action. But I think you tell us about efficient was going to stay a constant right? That is the basic idea behind the action.

Let's see with electronic AC to come back here is electronics Python. Three, you're good to go with our basically a lie that says hope to agree that I hope you're going to see that option argument here. Right. So this national debate about invasion so to run this can just go with it. That's that's good to see the program name and then debate to basically Alexa the program name is coming from this program here. Right since you have not changed it, which is being passed here.

And division is 0.01. So that is how to work with something busy about a class. So in the next session, I'm trying to see how to work it often argument and then the other I can see an initiation stablest

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.