I want the program to tell the user that the file he has wrote is not available (in case he wrote the name of a file that does not exist) and then to give him the oppourtinity to input a valid file name till he writes a valid file name.
def openfile(which_file):
with open(which_file, "r") as file:
file_rows=file.readlines()
passengers=[]
for lines in file_rows:
if lines !="\n":
objekt=carclass.data_manager(lines.split()[0], lines.split()[1], lines.split()[2], lines.split()[9], lines.split()[13])
passengers.append(objekt)
return passengers
def mainmenu():
which_file = input("Which file do you want to read?: ")
passengers = openfile(which_file)