Bug? 5/9 (Reading Between the Lines) 'text.txt' file not found

Bug?

On File Input/Output part 5/9 (Reading Between the Lines) I get an error like 'text.txt' file not found. The code is

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

I don't think there is anything wrong with the code because if I skipped this part and do the 6/9 (PSA: Buffering Data) first the text.txt file will be created and the 5/9 will run just fine.

5 Likes

Hi juancholas,

Yes, this is a bug. To workaround it, make any tiny change to text.txt, then go back to your php file and submit it again.

42 Likes

it’s as if the file did not exist

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

:confused:

Thanks albion. codecademy, please fix this bug? And perhaps explain the bug?

2 Likes

I’m also having the same issue, 10 days later, so it seems as if it has not been fixed.

I’m pretty sure it’s been like that for at least a year. Everyone just uses the workaround and moves on.

Works great, thank you!

Thanks, that workaround works!

(just bumping up this thread to get the bug fixed?)

I just recreated my_file in this exercise. There seems to be some bug, but this works fine for me. Too lazy to indent, sorry.

my_list = [i**2 for i in range(1,11)]
my_file = open(“text.txt”, “w”)
for item in my_list:
my_file.write(str(item) + “\n”)
my_file.close()

my_file = open(“text.txt”, “r”)
print my_file.readline()
print my_file.readline()
print my_file.readline()
my_file.close()

7 Likes

Bumpbumpbumpbumpbump

Still not working

Solution: write anything on the 4th line of text file.

17 Likes

Hi everyone!
Just add a space at the last line to modify de text and the problem will be solved.
This forces the file to be modified.
It worked for me.

10 Likes

Thanks, this worked for me! I just open the text file and click enter, and back to the code, resubmit

1 Like

Thanks, it’s good solution.

@albionsrefuge: good catch :slight_smile:

1 Like

this works well. thanks

You can alternatively leave script.py and text.py empty and it still works. Learning?

just use “r+” instead of “r”.
It worked for me :slight_smile:

It’s particularly strange. I think it has to to something with certain characters.

Happens the same thing in spanish version.

f = open("salida.txt","r")
print f.readline()
print f.readline()
print f.readline()
f.close()

is CORRECT and

f = open("texto.txt","r")
print f.readline()
print f.readline()
print f.readline()
f.close()

is WRONG.