【问题标题】:Unicode escape errorUnicode 转义错误
【发布时间】:2013-10-06 15:26:24
【问题描述】:

专家!

我正在尝试使用 Twython 创建一个 twitter 客户端。现在,我从交互式解释器中检索命令。

在一次上传图片的测试中,我通过了这个字符串:

   "tweet photo: 'tweeted from python test' + path: 'C:\Users\akhya_000\Pictures\My Pictures\Bing.png"

但我发现它无效并导致此错误:

SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 51-52: truncated \UXXXXXXXX escape

谁能帮帮我,字符串有什么问题?我该怎么做才能解决它?

【问题讨论】:

    标签: python unicode syntax-error unicode-escapes


    【解决方案1】:

    您想要转义反斜杠或使用原始字符串,因为 Python 看到 \U 并将其解释为 Unicode escape sequence

    转义看起来像这样:

    "tweet photo: 'tweeted from python test' + path: 'C:\\Users\\akhya_000\\Pictures\\My Pictures\\Bing.png"
    

    raw string,其中 Python 将忽略转义序列,如下所示:

    r"tweet photo: 'tweeted from python test' + path: 'C:\Users\akhya_000\Pictures\My Pictures\Bing.png"
    

    【讨论】:

      猜你喜欢
      • 2017-01-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-26
      • 2013-03-10
      • 1970-01-01
      • 2021-12-26
      相关资源
      最近更新 更多