Is it possible to add an Argument to an python argparse.ArgumentParser
without it showing up in the usage or help (script.py --help
)?
是否可以将一个Argument添加到python argparse.ArgumentParser而不显示在use或help(script.py --help)中?
1 个解决方案
#1
116
Yes, you can set the help
option to add_argument
to argparse.SUPPRESS
. Here's an example from the argparse documentation:
是的,您可以将add_argument的帮助选项设置为argparse.SUPPRESS。这是argparse文档中的一个示例:
>>> 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
#1
116
Yes, you can set the help
option to add_argument
to argparse.SUPPRESS
. Here's an example from the argparse documentation:
是的,您可以将add_argument的帮助选项设置为argparse.SUPPRESS。这是argparse文档中的一个示例:
>>> 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