import argparse
parser = argparse.ArgumentParser()
parser.add_argument('-d', '--date', help='date of event', type=str)
parser.add_argument('-t', '--time', help='time of event', type=str)
args = parser.parse_args()
print(f'Event was on {args.date} at {args.time}')
import argparse
# construct the argument parse and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-n", "--name", required=True, help="name of the user")
args = vars(ap.parse_args())
# display a friendly message to the user
print("Hi there {}, it's nice to meet you!".format(args["name"]))
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('file', type=argparse.FileType('r'))
args = parser.parse_args()
print(args.file.readlines())
import argparse
if __name__ == "__main__":
#add a description
parser = argparse.ArgumentParser(description="what the program does")
#add the arguments
parser.add_argument("arg1", help="advice on arg")
parser.add_argument("arg2", help="advice on arg")
# .
# .
# .
parser.add_argument("argn", help="advice on arg")
#this allows you to access the arguments via the object args
args = parser.parse_args()
#how to use the arguments
args.arg1, args.arg2 ... args.argn
# importing required modules
import argparse
# create a parser object
parser = argparse.ArgumentParser(description = "An addition program")
# add argument
parser.add_argument("add", nargs = '*', metavar = "num", type = int,
help = "All the numbers separated by spaces will be added.")
# parse the arguments from standard input
args = parser.parse_args()
# check if add argument has any input data.
# If it has, then print sum of the given numbers
if len(args.add) != 0:
print(sum(args.add))
parser.add_argument("arg1", type=int)
python Application.py -env="-env"