4.Reading - Why is this wrong?!


#1

I have this code:

and I keep getting this error message :
Traceback (most recent call last):
** File "python", line 1, in **
IOError: [Errno 2] No such file or directory: 'text.txt'

I don't understand how this doesn't work, could someone plz help?


#2

Hello Rachel,

i suppose that your text file is output.txt, but not text.txt!

So change your code here:

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

to

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

This should help you resolve this issue! :slight_smile:


#3

Thanks for the help, @markkarnaukh, but unfortunately it is still not working, any ideas?


#4

@rachel_sugden, it seems that something is wrong with this task! Today iit works fine for me too, but now i have the same error message!

I will flag this to the code academy moderation team...


#5

Okay thanks, but I have to finish this python course for before I go back to school next week so is there another way I can complete this lesson? @markkarnaukh :relaxed:


#6

I will flag this to the code academy moderation team...

You don't need to do that - it looks like this is a temporary problem - they normally come and go often like this one.


#7

Done, now we need to wait for a response! :wink:


#8

Thanks for information! :slight_smile:


#9

Cheers! @markkarnaukh :stuck_out_tongue_winking_eye:


#10

This should help:


#11

You need to clear out and replace the content of your 'output.txt' file - which is in 2nd tab.

Thanks,


#12

This worked for me:
Switch to the output.txt file and add some random text.
Follow the instructions given in the task using "output.txt" as the file name (resulting in code line 1).
Call "my_file.write(...)" with "..." containing code of your choice.
DO NOT close out my_file. You will get an error that it is not open.


#13

This seems to be a bug in the Codecademy system.
I replaced the existing text.txt file with the same text like below and then it can be opened.

list= ["I'm the first line of the file!\n", "I'm the second line.\n", "Third line here, boss.\n"]

my_file = open("text.txt" , "w")
for line in list:
my_file.write(line)
my_file.close()
my_file = open("text.txt", "r")
print my_file.readline()
print my_file.readline()
print my_file.readline()


#14

Worked also for me! THX!


#15

Yes, with any tiny change in text.txt it works, thanx!


#16

I am having the same problem. Stuck at 97%.


#17

Thank you so much. It has worked for me


#18