more-python/exercises/ex04/help

24 lines
952 B
Python
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python
# Exercise 4
# help arg
# 1. Getting help with -help or -h.
# 2. A least three arguments that are flags, meaning they dont 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)