问题:

  在使用join()将列表元素连接成字符串时出错如下

    return split.join(result)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xcb in position 0: unexpected end of data

原因分析:

  将list类型的result打印出来发现,部分元素是unicode编码,部分元素是utf8编码,而StringIO对象可以接受Unicode或8位字符串,但混合这两者就会出错

解决办法:

  遍历list将其中的每个元素转成str类型再join即可。

相关文章:

  • 2021-04-21
  • 2022-01-07
  • 2022-12-23
  • 2022-12-23
  • 2021-07-10
  • 2021-07-07
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案