loading...

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

erikkristoferanderson profile image Erik Kristofer Anderson ・1 min read

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 deleted the quotation at the end of a string. What I don't know is what EOL stands for. I assume it stands for something? A cursory googling just brought up obscure examples of people being surprised to get this error.
And while we're at it, what does 'literal' mean in this context?
Thanks,
Erik

If you're curious, here's the broken code:

do_not = "don't

Discussion

pic
Editor guide
Collapse
deciduously profile image
Ben Lovy

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.

Collapse
erikkristoferanderson profile image
Collapse
deciduously profile image
Ben Lovy

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!

Thread Thread
erikkristoferanderson profile image
Erik Kristofer Anderson Author

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

Collapse
aleksikauppila profile image
Aleksi Kauppila

I think it means ”end of line”.

Collapse
erikkristoferanderson profile image
Erik Kristofer Anderson Author

Thank! That's what Ben Lovy said also.