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
this is the error
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
1 2 3 4 5 6 7 8 9 |
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" ) |
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