Part of my code:
def get_file(): custom_data_folder = input("Name of custom data directory - " + "Hit ENTER to default: ") file_name = input("File name: ") default_path = os.path.abspath(os.path.join('data', file_name)) custom_path = os.path.abspath(os.path.join(custom_data_folder, file_name)) if custom_data_folder == '': return(default_path if os.path.exists(default_path) is True else "The file or path does not exist.") else: return(custom_path if os.path.exists(custom_path) is True else "The file or path does not exist.")
My script assumes a file is in a directory called "data", but I wanted to provide an option of a entering a custom directory where a file could be.
It works, but is there a better way to go about doing what this function is trying to accomplish?