5/9: what is the problem here


Anyone can help? I really don't understand the warning..


Please post a link to the lesson. The image helps us solve very little.


I'm sorry for lack of information.
The lesson is File Input/Output: 5/9 Reading between the lines


Stuck. Will get back to you when I've investigated further.


Hi @quitapenas ,

You need to read an entire line, so use the readline method ...

print my_file.readline()

That needs to be done three times.


I couldn't help with this exercise since it won't run for me:

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

SCT error message

Sorry, but I'm gonna need you to refresh the page! Don't worry your code is saved.

I'm wondering if this is a once through type of exercise, which having been completed on an earlier date is not re-doable?


I got that message from the beginning when I completed the exercise, it didn't work from the beginning and I now cannot complete the course overall because of this bug due most probably to the change between the use of output.txt earlier, to text.txt which means that the file isn't working with the code properly, if u have done what the guys appylpye said earlier

Then you have completed the exercise and no longer need to worry as long as you understand the process.



You can complete it but it requires a little wonkeyness because the server deletes the text file the user creates when they do the prior lesson. If there is a break in between sessions.

You can go to the earlier lesson and redo it for the file to get created again or you can do,

    my_file = open('text.txt', 'r')
    with open("text.txt", 'r') as file:
        for line in file:
    with open("text.txt", 'w+') as file:
        for i in range(3):
            file.write('{} {} \n'.format('New Line', i))
        for line in file:

This should allow you to pass the lesson, though I do have to say that teaching that particular method of opening and closing files is not Pythonic in the least.


It makes perfect sense to simply go back and redo the lesson that creates the text file in the first place. I had to do that to complete the Twitter API module since I had to go back to it a couple of times. Don't know why I didn't think to do that again. Too busy frittering around, one supposes. I do a tremendous amount of reading and fiddling in any given day and unfortunately, retain only bits and pieces.

I love that you included the above code example. It illustrates the mechanics in a very meaningful way. Thank you. My own ignorance of things Pythonic (though I can begin to imagine) leaves me devoid of any opinion on the matter. You'll have to elucidate me on this, in your own time, and perhaps as a topic for open discussion in the Corner Bar?


Only one problem... The previous lessons create 'output.txt', not 'text.txt'. Still same problem. Success using the try-except code. Thanks, again.


Thanks zeziba, with your code, the program ran without a problem, but I'm sure this isn't the method intended to complete the lesson. However, without it, I couldn't advance, so I guess it's a workaround instead of a solution.


The exercise is broken in that the file isn't created by the system. So you can edit the file manually, or add this:

with open('text.txt', 'w') as my_file:
    my_file.write('I\'m the first line of the file!\n')
    my_file.write('I\'m the second line.\n')
    my_file.write('Third line here, boss.\n')

or remove the curriculum_id part of the url which gets you a different submission test for this exercise which runs the above code and then asks you to submit again

The intended code does not pass the exercise as the exercise is broken.


I finished my lesson.
Sorry that I didn't detail my situation at the first time, that caused much difficulty on the investigation.
After passing the lesson, I tried to reproduce the warning "Oops,try again. It looks like you didn't print the first line from the text.txt", but I failed.
So I describe my steps according to my memory as below, hope it can help.
First, I wrote below code:

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

And got this error:

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

I refreshed the page several times as requested, but still got above problem.
I tried a solution found on QA forum, that enter space then remove it in "text.txt". Still got the problem.
Then tried another solution on QA forum, changed my code as below:

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

And got the warning "Oops,try again. It looks like you didn't print the first line from the text.txt".
I repeated entering and removing space in "text.txt", still failed.
Then I rolled back the code below and it passed.

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

Sorry for any inconvenience this may cause. I would like to close this question. Thank you all for your support.


I passed the lesson from

firstly wrote:
my_file = open("output.txt","r")

then modified it back to:
my_file = open("text.txt","r")

press "save & submit code". It works. Please try!


I don´t think so because I am gaving the same problem. I never passed it.


it doesn´t work for me, it still gives me:

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


Hi Saluszavalia, may you try same process as like above ways of "quitapenas"? She passed after a "try & error". I did the same way. good luck!


thanks for the help, I had the same problem, but It help me to pass the lesson.


I met the same problem~


Thanks for the code! I don't get it and have no idea how and why you wrote this...