Raw String Question

Jim Garrison jgarrison at troux.com
Thu Mar 12 20:54:56 CET 2009

Tim Chase wrote:
>>   >>> r"a\"
>>   SyntaxError: EOL while scanning string literal (<pyshell#45>, line 1)
>> It seems the parser is interpreting the backslash as an escape
>> character in a raw string if the backslash is the last character.
>> Is this expected?
> Yep...as documented[1], "even a raw string cannot end in an odd number 
> of backslashes".

So how do you explain this?

     >>> r'a\'b'

The backslash is kept, but it causes the following quote to be escaped.

More information about the Python-list mailing list