Look at your code:
def file():
file= input("Enter file name(test.txt): ")
try:
...
except:
print('File cannot be opened:', file)
file()
file()
So if the code reaches the exception, it prints a message, and then recursively calls the function it's already executing which does exactly the same thing again. And again. And again ...
Why are you calling
file
in the exception handler code?