Issue with reading between the lines


#1


https://www.codecademy.com/courses/python-intermediate-en-OGNHh/1/1?curriculum_id=4f89dab3d788890003000096

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

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


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


#2

i have tried refreshing the page, quitting the browser and restarting the computer.


#3

This is a known problem, see this topic:

Which discusses how you can create the file with python, and then read it as a workaround

Other people manipulate the file directly, this also works


#4

This worked wonders .... THANKS!

# Buggy exercise
# First, create the file
f = open("text.txt", "w") 

# Add 3 lines of text
f.write("Hello World!" + "\n") 
f.write("Hello World!!" + "\n") 
f.write("Hello World!!!" + "\n") 

# Close the file
f.close() 

# Then, open the file for reading 
# and proceed with the exercise
# as normal 
my_file = open("text.txt", "r") 

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

my_file.close()

#5