Why does it say there is no such file?

Question

Why does it say there is no such file?

Answer

Some users have had issues with the file they’re trying to open not existing, according to the terminal anyways. The solution seems to be making any slight change to the file, text.txt, and then going back to your Python file and running it again.
This is very unlikely to be the case, though. Be sure that you’ve properly opened the file by writing my_file = open("text.txt", "r").
Then you can print the result of my_file.readline() three times to see the three lines of the text file!

2 Likes

does my_file.readline() function come with a new line printing out in the end by default ?

i run my_file.readline() three times and the result show as below

I'm the first line of the file!

I'm the second line.

Third line here, boss.
1 Like

try putting a common at the end of the print line:

print my_file.readline(),