4.Reading - Why is this wrong?!


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?


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


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

This should help you resolve this issue! :slight_smile:


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


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


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:


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.


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


Thanks for information! :slight_smile:


Cheers! @markkarnaukh :stuck_out_tongue_winking_eye:


This should help:


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



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.


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 = open("text.txt", "r")
print my_file.readline()
print my_file.readline()
print my_file.readline()


Worked also for me! THX!


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


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


Thank you so much. It has worked for me