编码转换时,通常需要以unicode作为中间编码,即先将其他编码的字符串解码(decode)成unicode,再从unicode编码(encode)成另一种编码。

python之decode、encode及codecs模块

1

2

str1.decode('gb2312')    # 将gb2312编码的字符串转换成unicode编码

str2.encode('gb2312')    # 将unicode编码的字符串转换成gb2312编码

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-09
  • 2022-12-23
  • 2022-12-23
  • 2021-10-11
  • 2021-07-19
猜你喜欢
  • 2021-12-23
  • 2022-12-23
  • 2021-07-21
相关资源
相似解决方案