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

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

问题描述

是否可以将参数添加到 python argparse.ArgumentParser 没有出现在用法或帮助中 (script.py --help)?

解决方案

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

<预><代码>>>>解析器 = argparse.ArgumentParser(prog='frobble')>>>parser.add_argument('--foo', help=argparse.SUPPRESS)>>>parser.print_help()用法:颤抖 [-h]可选参数:-h, --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)?

解决方案

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天全站免登陆