Command line args in Python :
When the program comes to Python , it's all about libraries .Argparser
is the library used for the taking inputs from the command line. Here
you can validate the arguments which are entered by the user without
writing the another function to validate from the if conditions.
suppose give a filename like cmdprocess.py
You can give the expecting arguments like below
cmdprocess.py --help
it will give the total arguments with respective commands to represent
Required =True :
When the required is true. You have to enter the argument.
Type = function name:
Type is very useful to validate the input entered by the user.
so that you can send a message like user need to enter the defined
arguments only. This function always expects the input argument .
YOU Can inherit the Exception class on this you can write your own exceptions like below
Custom-Exceptions In Python:
There are multiple exceptions which are already present in python like AssertionError, TypeError ...etc. But when you want implement your own Exceptions like whenever you see , you can say this one happened because of the particular problem is occurred .YOU Can inherit the Exception class on this you can write your own exceptions like below
class InvalidResolutionException(Exception): def __init__(self, code, message): self.code = code self.message = message
Total program:
If you don't know the which arguments needs to be parsed ,then do the --help command it will display the no of arguments and how to pass reference below.
Execute process |
Passing the arguments and resultant show the user entered arguments for different command inputs
When the programmer is added the required is true in the add_argument statement and , the user didn't choose to enter the argument then it will show the error like that required argument is missing
reference below.
Comments
Post a Comment