Skip to content
loading...

What does the 'EOL' stand for in 'SyntaxError: EOL while scanning string literal'

Erik Kristofer Anderson on July 22, 2019

I'm playing a game where I break my code and study the errors. I got this idea from "Learn Python the Hard Way." I know why I got the error: I dele... [Read Full]
markdown guide
 

It stands for End of Line. Here, it means that it was expecting to find a matching quotation, but instead hit the End of the Line without finding a match, which was unexpected.

Literal means you've got a literal representation of this string, i.e. the string itself in quotes. An array literal might be something like [1,2,3,4,5] - it's a bit of text that corresponds directly to the data type it represents.

Edit: the reason this syntax error comes out that way is because of the literal, actually. Though to a human the syntax error is that your quote isn't matched, what the parser was doing was attempting to read in a string literal to build its internal in-memory representation of a String from it. This isn't a multi-line string, so as it was reading in (scanning) the literal one token at a time, it ran into the end of a line. That's illegal in a string literal, thus this syntax error. Of course, the fix is to add the quote, which means the parser successfully reads the whole string literal and then moves on to the end of the line, where it now occurs in a valid, expected place.

 
 

I like this idea, intentionally breaking working code. You can learn a lot about how your language works from understanding why specifically you're getting a given error. Thanks for the tip!

Cool. I got the idea from "Learn Python the Hard Way' and I'm definitely going to continue using it.

 
code of conduct - report abuse