我有一个参数,它是一个1-100之间的整数,我不喜欢它在使用argparse时出现在-h帮助消息中的方式(它实际上列出了0、1、2、3、4、5,。。。等)
有什么方法可以改变这一点,或者用另一种方式来表现它?
谢谢
编辑:
以下是询问者的代码:
norse = parser.add_argument_group('Norse')
norse.add_argument('-n', '--norse', required=False, help='Run the Norse IPViking scan.', action='store_true')
norse.add_argument('--threshold', required=False, type=int, choices=range(0,101), help='Threshold (0-100) denoting at what threat level to provide additional data on an IP \
address. Default is 49.', default=49)
使用} parameter 。
add_argument()
的^{例如:
测试:
结果
使用自定义的
type
,更容易控制错误消息(通过ArgumentTypeError
)。我仍然需要metavar
来控制用法显示。生产:
我可以使用
functools.partial
自定义范围值:您可以自定义操作,例如:
测试它:
相关问题 更多 >
编程相关推荐