美文网首页
python中unicode转中文,\u559c\u6b22\u

python中unicode转中文,\u559c\u6b22\u

作者: Zooee | 来源:发表于2016-08-15 20:03 被阅读284次

你巧了, 之前帮过别人类似的问题了。

先说答案:

yourSlushUStr = "\\u559c\\u6b22\\u4e00\\u4e2a\\u4eba";

decodedUnicodeStr = yourSlushUStr.decode("unicode-escape")

就可以把你的

\u559c\u6b22\u4e00\u4e2a\u4eba

解码为:

喜欢一个人

了。

具体解释,参考:

【整理】Python中,如何将反斜杠u类型(\uXXXX)的字符串,转换为对应的unicode的字符

(此处不给贴地址,请自己用google搜帖子标题,即可找到帖子地址)

追问:

我print的时候会显示

UnicodeEncodeError: 'latin-1' codec can't encode characters in position 0-4: ordinal not in range(256)

怎么回事呢?亲

追答:

1.你最后去看看:

【总结】Python 2.x中常见字符编码和解码方面的错误及其解决办法

【整理】Python中字符编码的总结和对比:Python 2.x的str和unicode vs Python 3.x的bytes和str

这对你现在的错误,和以后可能犯的错误,都有帮助。

2.对于你这里的问题,请把:

A。相关的代码贴出来

我才好帮你看看,是哪些内容打印错误了。

相关文章

网友评论

      本文标题:python中unicode转中文,\u559c\u6b22\u

      本文链接:https://www.haomeiwen.com/subject/aunusttx.html