打印:

print('我喜欢你'.encode('unicode_escape'))

得到Unicode编码:

b'\\u6211\\u559c\\u6b22\\u4f60

 

将上面的编码赋值给str后解码:

#Unicode
s1='\\u6211\\u559c\\u6b22\\u4f60'

#转为utf-8(明文)
print(s1.encode('utf8').decode('unicode_escape'))
#转为utf-8编码
print(s1.encode('utf8').decode('unicode_escape').encode('utf8'))

输出:

我喜欢你
b'\xe6\x88\x91\xe5\x96\x9c\xe6\xac\xa2\xe4\xbd\xa0'

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-19
  • 2022-12-23
  • 2021-09-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-10-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-02
  • 2021-05-20
  • 2022-12-23
相关资源
相似解决方案