小编Yoa*_*yun的帖子

Python Argparse - 如何将文本添加到默认帮助消息中?

我正在使用python的argparse来处理参数的解析.我得到一个默认的帮助消息,结构如下:

usage: ProgramName [-h] ...

Description

positional arguments:
  ...

optional arguments:
  -h, --help            show this help message and exit
  ...
Run Code Online (Sandbox Code Playgroud)

我想要的是在此消息中添加一个全新的部分,例如:

usage: ProgramName [-h] ...

Description

positional arguments:
  ...

optional arguments:
  -h, --help            show this help message and exit
  ...

additional information:
  This will show additional information relevant to the user.
  ....
Run Code Online (Sandbox Code Playgroud)

有没有办法实现这种行为?python 2.7和3.x都支持的解决方案是首选.

编辑:我还希望有一个解决方案,将在帮助消息的底部添加新的部分/部分.

python python-2.7 argparse python-3.x

9
推荐指数
2
解决办法
4519
查看次数

标签 统计

argparse ×1

python ×1

python-2.7 ×1

python-3.x ×1