all Python 3argparseterm
argparse.ArgumentDefaultsHelpFormatter
help formatters
A help formatter that appends each argument's default value to its help: '(default: 3)'. It saves you from repeating the default in the text by hand.
Syntax
argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
The default is appended only to arguments that have help: an argument without help gets no note even if it has a default. Arguments without a default show '(default: None)', which confuses users; if you write %(default)s into a help string yourself, the formatter will not add it a second time.
Examples
import argparse
parser = argparse.ArgumentParser(
prog='app', formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--n', type=int, default=3, help='сколько раз')
parser.add_argument('--name', default='x')
print(parser.format_help()) # → --n N сколько раз (default: 3) / --name NAME
See also
Open in the full glossarydocs.python.orgReport an inaccuracy