Answers for "python argparse option groups"

0

python argparse option groups

import argparse

parser = argparse.ArgumentParser(description='Foo', add_help=False)

required = parser.add_argument_group('required arguments')
required.add_argument('-i', '--input', help='Input file name', required=True)

optional = parser.add_argument_group('optional arguments')
optional.add_argument("-h", "--help", action="help", help="show this help message and exit")
optional.add_argument('-o', '--output', help='Output file name', default='stdout')

args = parser.parse_args()

# Access parser variables with
args.input
args.output
Posted by: Guest on May-19-2021

Python Answers by Framework

Browse Popular Code Answers by Language