Last active
March 13, 2021 14:29
-
-
Save yalin/6ba54e5e6628034e461e5088aa989113 to your computer and use it in GitHub Desktop.
Python argparser init
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# argprase library that will help us to deal with arguments | |
import argparse | |
import sys | |
myParser = argparse.ArgumentParser(description='Definition of the python file') | |
myParser.add_argument('mandatory', | |
type=str, | |
help='Mandatory argument') | |
myParser.add_argument('--optional', '-o', | |
metavar='str', | |
type=str, | |
help='Optional argument') | |
myParser.add_argument('--default', '-d', | |
default='defaultValue', | |
help='Argument with default value') | |
myParser.add_argument('--list', '-l', | |
metavar='element', | |
nargs='+', | |
help='Argument list') | |
requiredArgs = myParser.add_argument_group('required arguments') # a new argument group added | |
requiredArgs.add_argument('--required', '-r', | |
type=str, | |
help='Required argument', | |
required=True) | |
argsList = myParser.parse_args() | |
print("argsList :", argsList) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment