Python program to Display Error Message for Non-Existed Files

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...

   

 

Subscribe For Daily Updates

100+ Python Pattern Examplespython pattern examples - star patterns, number patterns