Back Slash not allowed at the end of raw string?

yuhao hao.yu at yeah.net
Fri Nov 10 08:22:06 EST 2006


I'm using Python 2.5 on Windows XP Pro.
While testing for strings, I got the following result:

>>> r'c:\'
SyntaxError: EOL while scanning single-quoted string

>>> r'c:\nwin'
'c:\\nwin'

>>> r"c:\"
SyntaxError: EOL while scanning single-quoted string

>>> r'\n'
'\\n'

>>> r'\"'
'\\"'

It seemed that when a back slash is inside the raw string, 
it is correctly recognized as a normal character, not translated; 
but when put to the end, it raise an error.

And the message looks so strange:

>>> r"c:\"
SyntaxError: EOL while scanning single-quoted string


what does this message mean? I'm not using any single quote in the statement.
It this a bug or by design?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20061110/b422ce8a/attachment.html>


More information about the Python-list mailing list