Reading Between the Lines


#1

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

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

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

I get these errors when running the code. Any suggestions what is wrong please?

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

#2

Hi, @aviss ,

Does it work if you refresh the page, and then submit the code?
If not, you can try this ...

# Buggy exercise

# First, create the file
f = open("text.txt", "w")
f.write("Hello World!" + "\n")
f.write("Hello World!!" + "\n")
f.write("Hello World!!!" + "\n")
f.close()
# Then, read the file
my_file = open("text.txt", "r")
print my_file.readline()
print my_file.readline()
print my_file.readline()
my_file.close()

Help in Reading Between the lines
Oops, try again. Sorry, but I'm gonna need you to refresh the page! Don't worry your code is saved. I tried to refresh on my browser, but didn't work. Is there another refresh button?
Stuck at reading between the lines
Reading between lines
Text.txt does not exist Error
#3

No, it doesn't. But yes, writing to a file first helps. Thanks.


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.