DEV Community

Erik Anderson
Erik Anderson

Posted on

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

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
~~~~
Enter fullscreen mode Exit fullscreen mode

Top comments (7)

Collapse
 
deciduously profile image
Ben Lovy • Edited

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
 
ekand profile image
Erik Anderson

Thanks!

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
 
ekand profile image
Erik Anderson

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

Collapse
 
johnmalib profile image
johnmalib

An EOL ( End of Line ) error indicates that the Python interpreter expected a particular character or set of characters to have occurred in a specific line of code, but that those characters were not found before the end of the line . This results in Python stopping the program execution and throwing a syntax error .

The SyntaxError: EOL while scanning string literal error in python occurs when while scanning a string of a program the python hit the end of the line due to the following reasons:

  • Missing quotes
  • Strings spanning multiple lines
Collapse
 
aleksikauppila profile image
Aleksi Kauppila

I think it means ”end of line”.

Collapse
 
ekand profile image
Erik Anderson

Thank! That's what Ben Lovy said also.