使用Python argparse创建隐藏参数 [英] Creating hidden arguments with Python argparse

查看:127
本文介绍了使用Python argparse创建隐藏参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将参数添加到python argparse.ArgumentParser ,而不会显示用法或帮助(script.py --help)中的内容?

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

推荐答案

是的,您可以将help选项设置为add_argumentargparse.SUPPRESS.这是 argparse文档中的示例:

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

这篇关于使用Python argparse创建隐藏参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆