考虑以下:
parser.add_option("-f", "--file", "--secret", action = "append", type = "string", dest = "filename", default = [], help = "specify the files")
Run Code Online (Sandbox Code Playgroud)
我想在调用帮助时向用户隐藏 --secret 选项。我可以通过以下方式做到这一点吗?
parser.add_option("-f", "--file", action = "append", type = "string", dest = "filename", default = [], help = "specify the files")
parser.add_option("--secret", action = "append", type = "string", dest = "filename", default = [], help = "specify the files")
Run Code Online (Sandbox Code Playgroud)
我这样做是否遗漏了任何隐藏的问题?如果是这样,任何人都可以建议一种替代方法来实现这一目标。
尝试这个help=SUPPRESS_HELP技巧(参见文档):
from optparse import OptionParser, SUPPRESS_HELP
parser.add_option("-f", "--file", action = "append", type = "string", dest = "filename", default = [], help = "specify the files")
parser.add_option("--secret", action = "append", type = "string", dest = "filename", default = [], help=SUPPRESS_HELP)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2246 次 |
| 最近记录: |