解决‘gbk‘ codec can‘t decode byte 0xab in position 13: illegal multibyte sequence

it2024-02-22  63

原代码:

fb = open(self.caseListFile) for value in fb.readlines(): data = str(value) if data != '' and not data.startswith("#"): self.caseList.append(data.replace("\n", "")) fb.close()

报错:

'gbk' codec can't decode byte 0xab in position 13: illegal multibyte sequence

修改为:读取文件时增加encoding=‘UTF-8’(第一行),成功解决问题

fb = open(self.caseListFile, encoding='UTF-8') for value in fb.readlines(): data = str(value) if data != '' and not data.startswith("#"): self.caseList.append(data.replace("\n", "")) fb.close()
最新回复(0)