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


#1

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/9: what is the problem here
Open("text.txt") doesn't work
Annoying bug that doesn't let me finish!
#2

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.


4.Reading - Why is this wrong?!
Reading Between the Lines (Python). BUG!
#3

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:


#4

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


#5

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


#6

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


#7

Works great, thank you!


#8

Thanks, that workaround works!

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


#9

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


#10

Bumpbumpbumpbumpbump

Still not working


#11

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


#12

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.


#13

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


#14

Thanks, it's good solution.


#15

@albionsrefuge: good catch :smile:


#16

this works well. thanks


#17

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


#18

just use "r+" instead of "r".
It worked for me ^__^


#19

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


#20

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.