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


#1

as title,

my code looks like this:

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

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!


#2

my_file=1
my_file= open('output.txt', 'r')
print my_file.read()
my_file.close()
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.


#3

Currently happening to me, too.


#4

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.


#5

I did it and It is really works!


#6

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


#7

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


#8

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


#9

first create the file

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

then close the file

my_file.close()

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")


#10

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

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

my_file.close()

^^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.


#13

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


#14

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


#15

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


#16

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...


#17

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.


#18

What is wrong with my code


#19

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]


#20

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


#21

Thank you! Now that's works. thumbs up


#22

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