python argparse option groups

Solutions on MaxInterview for python argparse option groups by the best coders in the world

showing results for - "python argparse option groups"
Meredith
23 Aug 2018
1import argparse
2
3parser = argparse.ArgumentParser(description='Foo', add_help=False)
4
5required = parser.add_argument_group('required arguments')
6required.add_argument('-i', '--input', help='Input file name', required=True)
7
8optional = parser.add_argument_group('optional arguments')
9optional.add_argument("-h", "--help", action="help", help="show this help message and exit")
10optional.add_argument('-o', '--output', help='Output file name', default='stdout')
11
12args = parser.parse_args()
13
14# Access parser variables with
15args.input
16args.output