fp = input("Enter file path: ") try: file = open(fp) except FileNotFoundError: print("Error! This file path does not exist...") else: print(file.read())
Output:
Enter file path: c:/python.txt Error! This file path does not exist...
100+ Python Pattern Examples