all Python 3argparseterm
argparse.RawDescriptionHelpFormatter
help formatters
A help formatter that keeps line breaks and indentation in description and epilog. The help text of individual arguments is still reflowed.
Syntax
argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter)
It suits a description with usage examples or a list: they keep their layout. A common mistake is to expect argument help to keep line breaks too — it does not, that text is still reflowed; you need RawTextHelpFormatter for that. Formatters are passed as a class to formatter_class=, without parentheses, and cannot be combined in one parser except through a common subclass.
Examples
import argparse
parser = argparse.ArgumentParser(
prog='app', description='Строка 1\n Строка 2',
formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument('--n', help='сколько\nраз')
print(parser.format_help()) # → Строка 1 / Строка 2 / сколько раз — help склеен
See also
Open in the full glossarydocs.python.orgReport an inaccuracy