I'm pretty new to python and im wondering whats the best way is to stucture and build my code in a specific data validation case. I'm building cmd line script that takes 3 arguments and save them to variables. The third argument is optional. How should i handle the optional argument. I get promted for "IndexError: list index out of range" when im not specifing the third argument.
Whats the most simple and practical why to validate user input with a optional argument?
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()
and len(user_guid) == Falseis going to be true (boolis a subtype ofint), but very confusing to read.