EOL while scanning string literal (After working around open("text.txt") problem)


#1



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


File "python", line 1
I'm the first line of the file!
^
SyntaxError: EOL while scanning string literal


It should read and print the line just fine? This was after i worked around the open("text.txt") error by adding an empty line to text.txt


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

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

my_file.close()


#2

Hi @adlerchua,

You need to have at least three lines in the text.txt file, because your code contains three of these ...

print my_file.readline()

Place at least three lines of text in the file so that your program runs successfully and produces visible output.


#3

Yeah this is what's in the text
"
I'm the first line of the file!
I'm the second line.
Third line here, boss.

"


#4

If it is still not working, try adding this or something similar with text of your choice to the beginning of your code ...

# Buggy exercise
# Create the file, so that it can be read.
f = open("text.txt", "w+")
f.write("Hello World!" + "\n")
f.write("Hello World!!" + "\n")
f.write("Hello World!!!" + "\n")
f.close()
# Add code below for opening, reading, and closing the file.

#5

It worked! Thanks so much!! :slight_smile:


#6