If you just want to override one parameter, you cannot use RawTextHelpFormatter . Instead, subclass HelpFormatter and provide a special introduction for the parameters that should be processed "raw" (I use "R|rest of help" ):
import argparse class SmartFormatter(argparse.HelpFormatter): def _split_lines(self, text, width):
And use it:
from argparse import ArgumentParser from textwrap import dedent parser = ArgumentParser(description='test') parser.add_argument('--list', help=dedent("""\ R|abc def ghi """)) parser.parse_args()
Any other calls to .add_argument() where help does not start with R| will be wrapped as usual.
This is part of my argparse improvements . Full SmartFormatter also supports adding default values ββfor all parameters and the initial input of the utility description.
source share