代码之家  ›  专栏  ›  技术社区  ›  AntoineLB

python:arg_parser参数添加别名

  •  0
  • AntoineLB  · 技术社区  · 6 年前

    我试图用python参数解析进行一些特定的打印,但是有些事情我做不到。

    parser.add_argument('-m' , help="test a specific module")
    

    上面是我的代码。

    optional arguments:
      -h, --help   show this help message and exit
      -m M         test a specific module
    

    以上就是结果。

    但我想要的是:

    optional arguments:
      -h, --help   show this help message and exit
      -m MODULE    test a specific module
    

    我知道这不是很重要,但我真的很想有这个输出。

    谢谢!

    1 回复  |  直到 6 年前
        1
  •  2
  •   Roelant    6 年前

    这可以通过添加 metavar

    parser.add_argument('-m', metavar='MODULE', help="test a specific module")