Creating hidden arguments with Python argparse

前端 未结 2 1431
旧巷少年郎
旧巷少年郎 2020-12-08 12:29

Is it possible to add an Argument to an python argparse.ArgumentParser without it showing up in the usage or help (script.py --help)?

2条回答
  •  一向
    一向 (楼主)
    2020-12-08 12:59

    Yes, you can set the help option to add_argument to argparse.SUPPRESS. Here's an example from the argparse documentation:

    >>> parser = argparse.ArgumentParser(prog='frobble')
    >>> parser.add_argument('--foo', help=argparse.SUPPRESS)
    >>> parser.print_help()
    usage: frobble [-h]
    
    optional arguments:
      -h, --help  show this help message and exit
    

提交回复
热议问题