嘿嘿哈哈

Python3中如何得到Unicode码对应的中文?
先检查text是什么类型如果type(text) is bytes,那么text.decode('unicode_...
扫描右侧二维码阅读全文
05
2018/10

Python3中如何得到Unicode码对应的中文?

先检查text是什么类型

如果type(text) is bytes,那么text.decode('unicode_escape')

如果type(text) is str,那么text.encode('latin-1').decode('unicode_escape')

s="对短信验证码共计应加强方法_杨玉龙"
print(bytes(s, encoding = "GBK"))
"""
结果显示:
b'\xb6\xd4\xb6\xcc\xd0\xc5\xd1\xe9\xd6\xa4\xc2\xeb\xb9\xb2\xbc\xc6\xd3\xa6\xbc\xd3\xc7\xbf\xb7\xbd\xb7\xa8_\xd1\xee\xd3\xf1\xc1\xfa'
"""

s1 = "\xb6\xd4\xb6\xcc\xd0\xc5\xd1\xe9\xd6\xa4\xc2\xeb\xb9\xb2\xbc\xc6\xd3\xa6\xbc\xd3\xc7\xbf\xb7\xbd\xb7\xa8_\xd1\xee\xd3\xf1\xc1\xfa"

print(s1.encode('latin-1').decode('GBK'))

"""
结果显示
对短信验证码共计应加强方法_杨玉龙
"""

链接:https://www.zhihu.com/question/26921730/answer/49625649

Last modification:October 5th, 2018 at 10:10 pm

Leave a Comment