I'm stuck on this question where after a FileNotFoundError
is caught, the user has to enter filenames until they enter a valid filename or Q to quit. I don't know what the valid filenames are so I cant do if filename != valid_filename
so I have to do a loop with FileNotFoundError
in it but don't know how. Here's what I got so far
def get_file_object(self):
try:
input_file = open(self.file_name, 'r')
words = input_file.read().split("/n")
except FileNotFoundError:
print("{} cannot be found.").format(self.file_name)
new_file_name = input("Please enter a valid file name or Q to quit:")