I am calling a function to get the file a user selects in a simple gui. I am trying to determine the proper way to continue prompting the user until they select a file. Right now my call is:
file_path = None
while file_path is None:
file_path = input_text_file() # calls function to prompt user
Is there a better way to do this without initially setting file_path to None? Is there a way to loop until a value is returned, or something along those lines?
If this is part of some form or wizard that requires the user to select a file, then you could simply check the value of file_path when the user clicks the continue or next button and if they have not selected a file then notify them in some way that they need to do so. This would not remove the need to set file_path = None but it would remove the while loop. If your set on just looping until a file is selected your way or lenik’s would work fine. Unless your doing some kind of dynamic updating of a part of your GUI based on the file selected then there may not be a need for the loop, but I don’t have enough info to be able to make that assumption.