BurningSilence 2020-11-23 16:34 采纳率: 0%
浏览 10

用python转码时,一个汉字占两个unicode时,转码报错

把下面的unicode编码转换成汉字

unicode: 

\\u5c0f\\ud84c\\uddc9\\u809d\\u4e32\\u4e32\\u9999

正确的汉字为:小𣇉肝串串香

下面是代码:

unicode_str = "\\u5c0f\\ud84c\\uddc9\\u809d\\u4e32\\u4e32\\u9999"
text = unicode_str.encode('utf-8', 'ignore').decode('unicode_escape')
print(text)
  • 写回答

1条回答 默认 最新

  • CruiseCai 2023-08-09 16:26
    关注

    可以用 cp1252代码集试一下:
    output[name].to_csv(outfile, float_format = '%.5f',index = False,encoding = 'cp1252')
    cp1252 编码是 ANSI/ASCII 的子集,因此可以使用 cp1252 编码生成 ANSI/ASCII 格式的 txt 文档。

    评论

报告相同问题?