Multiple lines in python argparse help display

后端 未结 3 2211
天涯浪人
天涯浪人 2021-02-13 00:41

I\'m using argparse in Python2.7 and I would like to display multiple lines in the help text of an argument.

My codes look like this:

import argparse

         


        
3条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-13 01:15

    The simplest thing you could do would be to place the lines in an array and then join them with newlines like so:

    help_lines = ['First line', 'Second line', '', 'More lines']
    # ...
    parser.add_argument('--argument', default=None, type=sometype,
    help='\n'.join(help_lines))
    

提交回复
热议问题