This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: SyntaxError: EOL while scanning string literal
Type: compile error Stage: resolved
Components: Interpreter Core Versions: Python 3.8
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: elonjigar, prasechen, steven.daprano
Priority: normal Keywords:

Created on 2020-09-04 12:12 by prasechen, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (5)
msg376361 - (view) Author: chen-y0y0 (prasechen) Date: 2020-09-04 12:12
# I try to run:
import os
os.system(r"start C:\Windows\System32\")
# But I get an Exception:
SyntaxError: EOL while scanning string literal
# A string after “r” means the string's original meaning. But……
msg376362 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2020-09-04 12:17
You can't end a string with a bare backslash, not even an raw string.
msg376363 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2020-09-04 12:23
See the FAQ:

https://docs.python.org/3/faq/design.html#why-can-t-raw-strings-r-strings-end-with-a-backslash

Also documented here:

https://docs.python.org/dev/reference/lexical_analysis.html#string-and-bytes-literals

Previous issues: #1271 and #31136
msg376682 - (view) Author: chen-y0y0 (prasechen) Date: 2020-09-10 12:33
Yep.
msg395309 - (view) Author: elonjigar (elonjigar) Date: 2021-06-08 07:11
An EOL while scanning string literal 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 . In most cases, this is  due to the following reasons:

    Missing quotes
    Strings spanning multiple lines

Strings can't normally span multiple lines. If you don't want the string to appear on multiple lines but you want to initialize it on multiple lines (so you can read it more easily), you can "escape" the newline by putting a backslash before the newline. If you want it to appear on multiple lines, you can use triple quotes around the string.

http://net-informations.com/python/err/eol.htm
History
Date User Action Args
2022-04-11 14:59:35adminsetgithub: 85882
2021-06-08 07:11:43elonjigarsetnosy: + elonjigar
messages: + msg395309
2020-09-10 12:57:00larrysetnosy: - larry
components: + Interpreter Core, - Argument Clinic
2020-09-10 12:33:32prasechensetmessages: + msg376682
2020-09-04 12:23:19steven.dapranosetmessages: + msg376363
2020-09-04 12:17:05steven.dapranosetstatus: open -> closed

nosy: + steven.daprano
messages: + msg376362

resolution: not a bug
stage: resolved
2020-09-04 12:12:06prasechencreate