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



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



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.


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.



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")
# Add code below for opening, reading, and closing the file.


It worked! Thanks so much!! :slight_smile: