"No such file or directory: 'text.txt'"


#1



https://www.codecademy.com/courses/python-intermediate-en-OGNHh/1/1?curriculum_id=4f89dab3d788890003000096#


I tried to open the file, but it says the file doesn't exist:

The console reads:
Traceback (most recent call last):
File "python", line 1, in <module>
IOError: [Errno 2] No such file or directory: 'text.txt'

and the error message keeps reading: "Oops, try again. Sorry, but I'm gonna need you to refresh the page! Don't worry your code is saved."


The file to be read


my_file = open("text.txt", "r")

print my_file.readline()
print my_file.readline()
print my_file.readline()

my_file.close()


#2

Looks like it resolved itself. Thanks.


#3

I am getting the same message. Code is correct and there is a 'text.txt' tab with three lines of text is visible. I have tried refreshing the page. If I use 'output.txt' as the file name it displays the same error message but also writes to the console "1

4

9

None"

Seems to be like a cache error ...


#4

Type something on the text.txt tab...

cf https://discuss.codecademy.com/t/5-9-reading-between-the-lines-error/42558


#5

Type something in the text.txt althought there has been something in it, then click "Save & Submit Code"


#6

my_file=open('text.txt','w')
my_file=open('text.txt','r')
print my_file.readline()
print my_file.readline()
print my_file.readline()
my_file.close()

I have the same problem and this solved it. Hope it helps.


#7

Why is there the 'w'?


#8

Thanks that solved it for me, typing into the file saved and created it so the code worked finally


#9

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.