Reading Between the Lines


#1



I think my code is correct, but I'm recieving an error message anyway


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

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


I followed the instructions and even went ahead with the lesson having no problem at all opening the .txt archive, I don't know why this part of the lesson is having a problem.


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

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

my_file.close()


#2

I even made another code caring about the message I got telling me the file could not be found, so I made a code where I create a file with the lines that are supposed to be printed and then proceeded to print them as the excersise says. Will attach the alternative code below:

my_file = open("C:\Users\Computer\Desktop\codecademy.txt", "w")
n = ["I'm the first line of the file!\n", "I'm the second line.\n", "Third line here, boss.\n"]
my_file.writelines(n)
my_file.close()
with open("C:\Users\Computer\Desktop\codecademy.txt", "r") as my_file:
print my_file.readline()
print my_file.readline()
print my_file.readline()

my_file.close()


#3

worked for me:

my_file1 = open("text.txt", "w")
n = ["I'm the first line of the file!\n", "I'm the second line.\n", "Third line here, boss.\n"]
my_file1.writelines(n)
my_file1.close()

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

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

my_file.close()


#4

In order for your code to work click on the text file and write on a few lines.


#5

You are not helping the user in any way by posting your own code. If you don't want to take the tie to help the user fix his code, it would be better if you refrain from posting. :slight_smile:

:no_entry_sign:


#6

I had the same problem and shared his code from comment with minor modifications.


#7

No, you posted your own code with no comments nor explanations. That is against community guidelines.


#8

Should I delete the post? вторник, 09 мая 2017г., 16:02 +07:00 от Dave codecademy@discoursemail.com :


#9

It would be good if you do


#10

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