我正在构建cmd行脚本,它接受3个参数并将它们保存到变量中。第三个参数是可选的。我应该如何处理可选的参数。 什么是最简单和实用的方法,为什么要用一个可选的参数来验证用户输入呢?user_cat = sys.argv[1]
user_id = sys.argv[2]
user_guid = sys.argv[3]
def validate(user_cat, argv_cat_list, user_guid):
if len(user_cat) > 10 or user_cat not in argv_cat_list:
print("Error! Please specify a valid category (AddDevice, GetAccount, c, p, GetDevices, r ,s)")
sys.exit()
elif len(user_id) == 36 or user_id.startswith("SAM-") and len(user_guid) == False:
getInfo()
sys.exit()
elif len(user_cat) >= 10 and len(user_guid) == 36 and user_id.startswith("FRA-"):
print ("Test-hest!")
else:
print("Error! Please specify a valid input")
sys.exit()