Python Glossary Русский

all Python 3argparseterm

argparse.RawTextHelpFormatter

help formatters

A help formatter that keeps whitespace and line breaks in all help text: both the description and every argument's help.

Syntax

argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter)

Wrapping to the terminal width is switched off for such text entirely: a long help line runs past the edge of the window, so you must split it yourself with '\n'. Consecutive blank lines are collapsed into one only in the description and epilog; in help they stay as written. If you only need line breaks in the overall description, prefer RawDescriptionHelpFormatter, which keeps automatic wrapping for arguments.

Examples

import argparse
parser = argparse.ArgumentParser(prog='app', formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument('--n', help='сколько\nраз')
lines = parser.format_help().splitlines()
print(lines[-2].strip())  # → --n N       сколько
print(lines[-1].strip())  # → раз

See also

Open in the full glossarydocs.python.orgReport an inaccuracy