March 22, 2018

Parsing Arguments and Options With Python Script

import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--file')
parser.add_argument('--debug', action='store_true')
args = parser.parse_args()

if args.debug:
        print(f"Options: {args}")

if args.file:
        with open(args.file) as fh:
                for line in fh:
                        print(line, end='')