如何约束每次只能使用一个可选参数调用Python脚本
我的目标是不能同时使用可选参数,这意味着每次只能使用其中一个选项调用脚本,下面是我的Python代码:如何约束每次只能使用一个可选参数调用Python脚本,python,scripting,argparse,Python,Scripting,Argparse,我的目标是不能同时使用可选参数,这意味着每次只能使用其中一个选项调用脚本,下面是我的Python代码: parser = argparse.ArgumentParser() parser.add_argument("-a", help="List out all the hostnames", action='store_true') parser.add_argument("-v", help="List out stude
parser = argparse.ArgumentParser()
parser.add_argument("-a", help="List out all the hostnames", action='store_true')
parser.add_argument("-v", help="List out student information", action='store_true')
parser.add_argument("-d", help="List out all the qualified domain name")
parser.add_argument("-c", help="List out all the qualified IPV4", choices=['A', 'B', 'C'])
parser.add_argument("filename", help="dataset name")
args = parser.parse_args()
另外,如果可选参数超出了选项(-a,-v,-d,-c)的范围,如何创建自定义输出,而不是使用args=parser.parse_args()
显示默认错误
谢谢你们,我真的很感谢你们的帮助 当用英语描述这种行为时,会弹出“互斥”表达式,快速查看Argparse可以确认Argparse有一个看起来有用的
add\u mutual\u exclusive\u group
方法