1

I want to keep newlines in help text and show defaults of arguments.

I found two answers at Stackoverflow:

How can I enable both features?

guettli
  • 25,042
  • 81
  • 346
  • 663
  • Don't forget that you can include ` %(default)s` in your own `help` lines - along with what ever extra formatting you want. See https://docs.python.org/3/library/argparse.html#help – hpaulj Jun 06 '18 at 06:19

1 Answers1

5
class SaneFormatter(argparse.RawTextHelpFormatter, 
                    argparse.ArgumentDefaultsHelpFormatter):
    pass

Usage:

    parser = argparse.ArgumentParser(description='''Multi
line
help
text
''', formatter_class=SaneFormatter)
guettli
  • 25,042
  • 81
  • 346
  • 663