Python Online compiler - OverIQ.com (original) (raw)

import os
filename = input("Enter file name: \n")

try:
    f = open(filename, "r")

    for line in f:
        print(line, end="")

    f.close()

except FileNotFoundError:
    print("File not found")

except PermissionError:
    print("You don't have the permission to read the file")

except FileExistsError:
    print("You don't have the permission to read the file")

except:
    print("Unexpected error while reading the file")

else:
    print("Program ran without any problem")