[New-bugs-announce] [issue31929] Raw strings create syntax error when last character is a single backslash
Barry
report at bugs.python.org
Thu Nov 2 17:27:46 EDT 2017
New submission from Barry <python-bugs at qsv.ca>:
Raw strings create syntax error when last character is a backslash (\).
This problem seems to exist across all versions of python (that I have access to)
Sample Code:
-------------------------------------------------------------
Under Windows Python 2.7.3
Works Correctly:
>>> test = r'C:\Program Files\^%(x86)\Internet Explorer\iexplore.exe'
>>> print test
C:\Program Files\^%(x86)\Internet Explorer\iexplore.exe
Fails because last character is backslash
>>> test = r'C:\Program Files\^%(x86)\Internet Explorer\'
SyntaxError: EOL while scanning string literal
-------------------------------------------------------------
Under Linux Python 2.7.12
Works Correctly
>>> j=r"\n"
>>> print j
\n
Fails because last character is backslash
>>> j=r"n\"
SyntaxError: EOL while scanning string literal
Works correctly:
>>> j=r"n\n"
>>> print j
n\n
Works correctly:
>>> j=r"n\\"
>>> print j
n\\
-------------------------------------------------------------
Under Linux Python 3.5.2
Fails because last character is backslash
>>> j=r"\'
File "<stdin>", line 1
j=r"\'
^
SyntaxError: EOL while scanning string literal
-------------------------------------------------------------
----------
components: Interpreter Core
messages: 305448
nosy: mezzzmer
priority: normal
severity: normal
status: open
title: Raw strings create syntax error when last character is a single backslash
type: compile error
versions: Python 2.7, Python 3.5
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue31929>
_______________________________________
More information about the New-bugs-announce
mailing list