In [18]: c = '你好'
In [20]: d = c.encode('unicode_escape')
In [21]: d
Out[21]: b'\\u4f60\\u597d'
In [23]: e = d.decode('utf-8')
In [24]: e
Out[24]: '\\u4f60\\u597d'
In [25]: type(e)
Out[25]: str
In [26]: f = e.encode('utf-8').decode('unicode_escape') # 在字符串中要将Unicode字符转换未中文,需要先编码.
In [27]: f
Out[27]: '你好'
原文地址:https://www.cnblogs.com/qianxunman/p/12375300.html
时间: 2024-11-10 14:02:34