Python2.7如何打印UnicodeScape格式字符串?

2024-09-29 17:17:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我知道python中的unicode字符串,就像u“blablabla”。它应该以“u”字开头。 但是我从一些api中找到了一些类似unicode的字符串

{"ret":"100015","msg":"\u5bc6\u7801\u8f93\u5165\u9519\u8bef\uff0c\u8fd8\u53ef\u4ee5\u8f93\u51654\u6b21","msg_new":"\u5bc6\u7801\u8f93\u5165\u9519\u8bef<br>\u8fd8\u53ef\u4ee5\u8f93\u5165<b>4<\/b>\u6b21"}

字符串不是以“u”字符开头的,所以我想知道如何处理这些字符串?在


Tags: 字符串apiunicodemsgblablablau53efu5165u8bef
1条回答
网友
1楼 · 发布于 2024-09-29 17:17:16

对于给定的str(在python3中,bytes)的字符以\uHHHH形式编码(unicode字符转义序列),可以使用unicode-escape编解码器对其进行解码。在

>>> s = "\u5bc6\u7801\u8f93\u5165\u9519\u8bef\uff0c\u8fd8\u53ef\u4ee5\u8f93\u51654\u6b21"
>>> type(s)
<type 'str'>
>>> r = s.decode("unicode-escape")
>>> type(r)
<type 'unicode'>
>>> print(r)
密码输入错误,还可以输入4次

相关问题 更多 >

    热门问题