ARGPARSE array code example
Example 1: python argparse
import argparse
ap = argparse.ArgumentParser()
ap.add_argument("-n", "--name", required=True, help="name of the user")
args = vars(ap.parse_args())
print("Hi there {}, it's nice to meet you!".format(args["name"]))
Example 2: how to use argparse
import argparse
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="what the program does")
parser.add_argument("arg1", help="advice on arg")
parser.add_argument("arg2", help="advice on arg")
parser.add_argument("argn", help="advice on arg")
args = parser.parse_args()
args.arg1, args.arg2 ... args.argn
Example 3: arg parse array argument
parser.add_argument("--list", nargs="+", default=["a", "b"])
SHELL
$ python3 example.py --list a b c
Example 4: parser.add_argument array python
parser.add_argument('-l','--list', nargs='+', help='<Required> Set flag', required=True)