Background -
I am attempting to implement some very basis error handling into a function, which accepts integer values (Entities and Views), separated by commas and stored in respective lists.
I have managed to error handle the entities_list
using a try
and except
, by simple printing an error message and then calling the function again (considering its the first user input in the function). However, although I can use else
to progress to the user's 2nd input / view_list
, I am not sure how to replicate the same error handling, without simply calling the function again, and thus the user has to unnecessarily input into the entities_list
again.
Any hints/tips on other blocks to use; I know my code is flawed, I just need some direction with where to research to solve this.
Code -
def user_inputs():
try:
entities_list = [int(x) for x in input("Entities for API Call:\n").split(', ')]
except:
print("---ERROR: MUST BE COMMA SEPERATED VALUES---")
user_inputs()
else:
views_list = [int(x) for x in input("Views for API Call:\n").split(', ')]
print("Must be comma seperated integer values")
user_inputs()