[issue1271] Raw string parsing fails with backslash as last character

R. David Murray report at bugs.python.org
Fri Mar 11 22:09:10 CET 2011


R. David Murray <rdmurray at bitdance.com> added the comment:

I think perhaps the language in the language reference is a bit misleading.  The purpose of the raw string algorithm is that any characters in the string be copied literally into the string object.  That is, \" "escapes" the " not so that you can write r"\"", but so that the string object produced by that literal (or by the literal r'\"') contains the two characters \".

So, it is certainly true that raw string will *not* be changed to make \ not escape quotes.

I can't remember where I read this, but the reason that a trailing \ is invalid has to do with the way the parser parses strings/raw strings.  So any alternate "more raw" string type would have to contend with the same parser issues that lead to the exiting restrictions on raw strings.

Unless someone wants to do a deep dive into the parser and figure out why things are they way they are and how to fix it, I think this issue should be reclosed.  Note that even if a solution can be found, if it significantly complicates the parser it will probably be rejected.  And I suspect it would, otherwise things probably wouldn't work the way they currently do.  However, perhaps someone can spot a clever solution that was overlooked in the original implementation.

----------
nosy: +r.david.murray
versions:  -Python 2.5, Python 2.6, Python 3.1

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue1271>
_______________________________________


More information about the Python-bugs-list mailing list