ArgParse - Types

Building Command Line Tools with Python, Julia and Nodejs Module 02 - Building Command Line Tools in Python with ArgParse
11 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 be trying to see how to work with types. So in the previous tutorials we have learned about how to work with basic creating a basic CLR with a class how to work it petitionary method of argument. So let's see another stuff about working with types. So in order to have been doing, you know, be specifying the type. So that means that anytime you run a class Eli, could I just a string or is a float is to point to a statistic, let's see an example.

I'll copy the basic CLR that we have and create a new file, which you call it as type CLR types and that's what CLA does.py right types sealer. So let me press it here. Let's see what I mean by that. So we have something very simple, important, everything straight away, quit and then innovation, just like the normal, but these ones don't have type. So if I run the same thing that we did to Python three, and then our types to like, Does that help? Everything is working as expected.

If I go with this option, you just eat right to eat is a number if I put in 20 is going to work, right? If I put in effort, you likely say 20 is still going to work, right? So that is not the best, right? So we should be able to restrict it to the point that is only taking the particular data type. So how do you do that? So the simplest way that you can specify the types when you are defining your argument.

So, let's try it. So this one is going to be type to be our string. So, that is how to specify it to be string, right. So, the devil is going to accept strength, by default expects everything as a strength. Very interesting. So, let's run it again and check out some modification to it.

So, we'll be changing this one's Hello, right? Let's go to the type. So are those particular type here to be sued by type, then they act But firstly, is something very busy. So I'll be adding that same thing to all of them. So I'll just come back here, we type, then I pass in the x, then for the face would be h, then the second one is going to be gender. Right?

So let's add these types admin to it. I'll copy this one here, search view to see what is being passed. Right? Perfect. Let's leave it there, right again. So our first one is a string by default, and this is going to be a number right, but we just going to type it as float or integer, we can just give it as an integer, then agender good to leave so that you see what the actual default type is when you supply it.

So let's come back here and run the same thing that we had. So each age is 20. Let's go with our list. First of all, check the help great hope now, let's see some basic information about it. Right. So this is something very interesting.

Then let's run it again. So we have our first name, let's do the transformer. This name is Jessica, the age is going to be 23 Then let's go with Dennis option of the agenda for the agenda is going to be right there only to go to C to also Hello Jessica, the type of crisis drink this as we defined here, right? So they type your string. So it's super detail a string, the type of the age was integer to the withdrawal, it's an integer, but the one we did not define automatically give us us string. So by default, every argument you're going to apply for an option is going to be a string, right?

So that is not the best you have to make sure that you actually commit it because it helps you make your work easier. So by that you can also come to this place here. Let's add something like that had salary Right and let's go with this option. Everybody likes Hello see that this could be just so for me, I can actually specify that your salary is I want to specify, we don't, we don't specify it so by somebody and I want to actually calculate this salary for the person can just create a sum of salary, sum of salary and just give us any name. Let's see, we added 43 to 40 plus x dot salary. Right.

So, that is how to use the argument that you are passing that you have stored inside your namespace to IQ so I can actually print that particular trait. So your salary is right, something like that. The nice really tight format not possible salary then the type is going to be extra salary argument dot salary. So let's bring this one on top of it. So save it here then let's talk about the commissioner there is nothing keeping right so print sum of salary the sum of salary is going to be with some salary. Let's see we'll run it again to understand it from here at now we are given time for this drink but firstly for the each for the agenda by the Salah we do not give it any type of way so let's make some changes so this must be corrected right so are we supposed to be add I commit but at Salah cafe so let's run it again and see what you have done so far.

Then just want to run Python three, then the name of types Eli that help you see the abuse I've got to do so everything is working perfectly right Now let's see how to run up, I just come back and run the previous one that you read, run and I'm going to add s for salary. Now passing the value of the city for Calgary is going to give us an error because by default, it is receiving it as a string. But because we are trying to add it here, it's not working right, we can add a string and number two is going to quick perfectly written records are to displace by 20, give it a salary, keep us on here, because it got added to it to this solution to this that can actually convert this one into a an into a flute here, then you can add it to if I do that, can I come back and I run it again.

Now is going to work right so that is one of the ways so I'm committing a string into an integer. This is not the best method. So the best method is to convert it at the top of it. So this come back to this place. And this is the type here to be integer selective It Right, and we don't need this one again. Because you have committed it, save it now and I come back to this particular place.

Let's run it again, as working perfectly like the previous one, right? That is one of the ways of the advantages of using type very, very interesting to show citizen to float to float. So we're going to keep it the same thing, or do I'm supplying an integer, so construct it and keep it to us as a float, right? Even though the various types there. So let's take a matter of seconds to do so there's another option of using choices. So apart from specifying a type to make a street can also specify a particular choice.

Right? So let's go with add a commit the list give it different types of jobs, right? So if there's any say types of jobs, we're left with a job type is the working remote or it's wicked on contract, right? That's the basic idea we are trying to specify if we gt then I'd like to be your job type. So your job type is remote. So how do you specify two different choices that a person can use, right?

You want to restrict them. This time I know she did them to a particular type, but we treated them to a particular option, right particular choice they must choose from. So it's going to be with choices. Then I specify a particular choice I wanted to so I can just go with a remote then there is only going to be full time, full time. So if I go to this option, when a person enters is going to select only these two choices without any aspect, we would allow any choice so let's come back to here to print and I'll see your job type. Okay, you You are a worker right now passing my job type x dot job type is listed with Alicia.

And again, I come back here. If it says this is an optional argument, I can go read it and it's going to make, right so you You are a non worker because it is optional, you get this position now, it's not going to quick go to give us an email. So let's add the job title for GT. For any number. So we have two different job sites, we have four, remote and then full time. So to be able to view this particular job type, there are two main ways of doing it.

So we can just come back to C followed by two or three, then Dyneema, type C Li, a Louis they hope option. And I ran it nice that's going to tell us the particular choice we have. So we have remotes and then food type. Very, very interesting right remotes and then food types with me that they can only select these particular two different types. So let's run it and then let's add the room. would soon to be GT and I cannot go with remote agree to him, it's going to work perfectly.

So you are very motivated if I go with a different in a performing motor when he was unable to have full time to work because four times a lot, but let's change it to contract, come up to the top and go with contract now has given us an error. So invalid choice contract is not part of it because it's not part of it. We must choose from either remote or full time. So the basic idea behind working with choices, right? we typed So in a nutshell, the server stuff can do types types allows you to come too fast and to follow a particular strict order. Very interesting.

So the basic idea that you're just going to do the normal things are between then you specify the type here with a type is equal to the particular date specified for files. It gives you a supply in a particular file to check is We're going to be a paragraph out. Thank you for watching and see you 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.