4/9 Reading : no such file/directory 'output.txt'


as title,

my code looks like this:

my_file = open("output.txt", "r")
print my_file.read()

I even copied the first line from exercise 2 and modified it, but it still doesn't work.

Is it a bug or I missed something? Thanks!


my_file= open('output.txt', 'r')
print my_file.read()
i have stuck in the same problem for several days, i add "my_file=1" at the beginning of the code just now ,then, it works,and i don not know why.


Currently happening to me, too.


Remove the my_file = 1. Go to to the output.txt file. Instantiate it by clicking anywhere i.e. put in a space then delete it. Then go back and run your code.

Another option is to try to refresh the page.


I did it and It is really works!


It worked, but this section has so many problems with not recognizing the output file...


Thank you so much!
I was so happy to get a 100% after this! :joy: :smiley: :rice_cracker:


Same problem, you have to go back to 3/9, click save&submit, then type the code, it will work.

I thin the output.tex is probably generated by 3/9


first create the file

my_file = open('output.txt', 'w')

then close the file


You will get an error, but you will have created the file so now you can open the file.
Be sure to delete the code the code above then the line will work.

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


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

for i in range (3):
print my_file.readline()


^^This is my code, I can see the .txt file, but the code error "Traceback (most recent call last):
File "python", line 1, in
IOError: [Errno 2] No such file or directory: 'text.txt'" and the codeacademy error "Oops, try again. Sorry, but I'm gonna need you to refresh the page! Don't worry your code is saved." just keeps coming up. I've been trying variations for days now.


I had similar problems, but when I changed the first line to my_file=open("text.txt", "r+") it ran through


Refreshing the page worked for me, thanks for the help bitwhiz16598


it works but is there any logic behind this or is it a bug?


It worked for me too, I feel like this a bug on Codecademy's part because there is no reason this shouldn't work otherwise...


I finally figured out. I go to the text.txt file and type a enter, and then try to submit again, it worked for me.


What is wrong with my code


Nothing is wrong with your code. It's a codeacademy bug. Go to the output.txt tab and put a space at the end of the file. Then switch back to the script.py tab and press [Save & Submit Code]


First open in "w" mode and then "r" (read )


Thank you! Now that's works. thumbs up


i can confirm that it is a bug, the output.txt isnt instantiated when the task is created.. so it cant be found

interacting with the file creates it