Bug in Lesson 5 or am I missing something?


This Code:

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

Gives me this error:

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

But the instruction tells me

calling open() on the "text.txt" file in "r"ead-only mode


i have the same problem


As another thread said, make a small edit in the "text.txt" file (which will force it to be saved again), then hit the "Save & Submit Code" button to re-run your solution.


That did not worked for me. I solved it by first using python to create that text.txt file with the 3 lines, before I read from thjat file:

new_file = open('text.txt', "w")
new_file.write("I'm the first line of the file!\n")
new_file.write("I'm the second line.\n")
new_file.write("Third line here, boss.\n")
my_file = open('text.txt', "r+")

print my_file.readline()
print my_file.readline()
print my_file.readline()



I added another random word as fourth line on "text.txt" tab and added a fourth "print my_file.readline()" on main tab and hit submit. In my case, only this fixed the bug.


Thanks, this works, bug fixed


thanks peshay..it did work..so we have to make this file first, write 3 line inside and then read it ..good work :grin:


As the rest said its a bug. Best thing to do is to go into the "text.txt" file tab beside the script.py tab on the top of the editor interface on codeacademy and put a space at the end of the 3rd line. I did that, then rewrote to file (r+ for read/write instead of a for append) and got success with the following code:

my_file = open('text.txt', "r+")
my_file.write("Hello file not working.\n")
my_file.write("Its 5 years as a bug.\n")
my_file.write("And another 5 to its fix.\n")

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

I was successful ONLY after I spaced the 3rd line of the text.txt file by jumping into it at the tabs on top of the editor interface where you have script.py | text.txt.


Its help me!


this bug still exist!


yep! that worked (:smile:


This is quite annoying :rage:
I spent so much time thinking I was the one with the problem. Please, fix the bug.


me too. it's the site i think


work for me, i add 1 to text file, then hit run, again i went to code, and it succeed


I don't know why but for some reason this code works. THank You !!


Are there any plans to fixing this bug??


Nice it worked a charm :slight_smile: