22 lines
918 B
Python
22 lines
918 B
Python
# Exercise 1
|
||
# 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()
|
||
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')
|
||
args = parser.parse_args()
|
||
print(args)
|