Hai everybody,
i write a code to open a txt file by input method but I am getting an error can any body help me.
this is the code
i write a code to open a txt file by input method but I am getting an error can any body help me.
this is the code
import os file = input("enter the file name: ") if os.path.exists(f"{file.lower().strip()}.txt"): open(f"{file.lower().strip()}.txt", "r") print(file.read()) else: print("the file does not exist")this is the error
Output:enter the file name: laxmi
Error:Traceback (most recent call last):
File "C:/Users/LAXMIDHAR/PycharmProjects/demo/input fun.py", line 7, in <module>
print(file.read())
AttributeError: 'str' object has no attribute 'read'
Process finished with exit code 1