1 1.TypeError: must be str, not bytes错误:
 2 
 3 解答: 写文件处 open(filename, 'w').write 应该写为 open(filename, 'wb').write
 4 
 5 2.当文本文件里面有中文时,需要进行编码转换,(在网上查了很多都不行)
 6 
 7 with open("C://ch.js", encoding="utf-8") as data1:
 8 for oneLine in data1:
 9 print(oneLine)
10 
11 编码转换:content = str(open(filepath).read(),'gbk').encode('utf8')
12 
13 当输出多一个b时加个decode(‘utf-8’)即可

 

相关文章:

  • 2022-12-23
  • 2021-11-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-02-05
  • 2022-12-23
  • 2022-12-23
  • 2021-11-16
  • 2021-08-06
相关资源
相似解决方案