Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

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
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #python #argparse #option #groups
ADD COMMENT
Topic
Name
7+8 =