Is It Bug?

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


On Sun, Dec 8, 2013 at 9:01 PM, Chris “Kwpolska” Warrick
<kwpolska at gmail.com> 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"
'asdfqwer'

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

>>> p"\b""\d+""\b"
'\\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.

ChrisA



More information about the Python-list mailing list