Python忽略文本中非utf8字符

错误信息:

‘utf-8’ codec can’t decode byte 0xa0 in position 1108 invalid start byte

处理方法:

以byte方法打开文件,忽略掉非utf8字符,然后存入一个临时文件

line = line.decode("utf-8", "ignore")
  • “ignore”:可忽略非utf-8字符

Related Posts