这算是一个Python语法解析的缺陷。
即使是在raw字符串中,引号(不仅是末尾的引号)仍然会受到转义字符串的影响。所以当字符串结尾之前存在奇数个反斜杠时,末尾的引号就会被转义,导致字符串没有引号来表示结尾,从而导致语法错误。
以下为文档内容:String quotes can be escaped with a backslash, but the backslash
remains in the string; for example, r"\"" is a valid string literal
consisting of two characters: a backslash and a double quote; r"\" is
not a valid string literal (even a raw string cannot end in an odd
number of backslashes). Specifically, a raw string cannot end in a single backslash (since the backslash would escape the following quote character).