Is It Bug?

Chris Angelico rosuav at
Sun Dec 8 11:26:39 CET 2013

On Sun, Dec 8, 2013 at 9:01 PM, Chris “Kwpolska” Warrick
<kwpolska at> wrote:
> A raw string cannot end with a backslash.
>>>> r'a\a'
> 'a\\a'
>>>> r'a\'
>   File "<stdin>", line 1
>     r'a\'
>         ^
> SyntaxError: EOL while scanning string literal

Incidentally, the solution to this would be to not use the backslash
to escape the quote. That's what introduces the ambiguity. Instead, a
raw literal could do as REXX does and double the quote to escape it.
(Any whitespace and it's still concatenation as normal. I'm not
advocating REXX's handling there.)

>>> r"asdf""qwer"

If we had a new "pure string" that worked thus:
>>> p"asdf""qwer"

>>> p"\b""\d+""\b"

which would be a regex matching quoted strings of digits. The only
potential ambiguity would be in that closing the quote and opening
another would normally revert to a regular string literal, where by
this model it's still a pure string. Editor lexers would have to
understand that.


More information about the Python-list mailing list