1import argparse
2
3# construct the argument parse and parse the arguments
4ap = argparse.ArgumentParser()
5ap.add_argument("-n", "--name", required=True, help="name of the user")
6args = vars(ap.parse_args())
7
8# display a friendly message to the user
9print("Hi there {}, it's nice to meet you!".format(args["name"]))
1# Generic parser function intialization in PYTHON
2def create_parser(arguments):
3 """Returns an instance of argparse.ArgumentParser"""
4 # your code here
5
6 parser = argparse.ArgumentParser(
7 description="Description of your code")
8 parser.add_argument("argument", help="mandatory or positional argument")
9 parser.add_argument("-o", "--optional",
10 help="Will take an optional argument after the flag")
11 namespace = parser.parse_args(arguments)
12
13 # Returns a namespace object with your arguments
14 return namespace
15