【发布时间】:2012-06-25 10:53:15
【问题描述】:
我在这里感到困惑,即使原始字符串将每个 \ 转换为 \\,但是当这个 \ 最后出现时,它会引发错误。
>>> r'so\m\e \te\xt'
'so\\m\\e \\te\\xt'
>>> r'so\m\e \te\xt\'
SyntaxError: EOL while scanning string literal
更新:
现在Python FAQs 也涵盖了这一点:Why can’t raw strings (r-strings) end with a backslash?
【问题讨论】: