2023-02-24 13:29:53 -06:00
|
|
|
|
# Exercise 4
|
2023-02-13 13:57:10 -06:00
|
|
|
|
# 1. Getting help with -help or -h.
|
|
|
|
|
# 2. A least three arguments that are flags, meaning they don’t take an extra
|
|
|
|
|
# argument but simply putting them on the command line turns something on.
|
|
|
|
|
# 3. At least three arguments that are options, meaning they do take an
|
|
|
|
|
# argument and set a variable in your script to that option.
|
|
|
|
|
# 4. Additional “positional” arguments, which are lists of files at the end of
|
|
|
|
|
# all the – style arguments and can handle Terminal wildcards like */.txt.
|
|
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser()
|
2023-02-24 13:29:53 -06:00
|
|
|
|
parser.add_argument("filename")
|
|
|
|
|
parser.add_argument("-o1", "--opt1")
|
|
|
|
|
parser.add_argument("-o2", "--opt2")
|
|
|
|
|
parser.add_argument("-o3", "--opt3")
|
|
|
|
|
parser.add_argument("-f1", "--flag1", action="store_true")
|
|
|
|
|
parser.add_argument("-f2", "--flag2", action="store_true")
|
|
|
|
|
parser.add_argument("-f3", "--flag3", action="store_true")
|
2023-02-13 13:57:10 -06:00
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
print(args)
|