python|读取文件含有中文的时候有报错的情况

xiaoxiao2021-02-28  35

f = open(file=file,'r')

data = f.read()

当file中含有中文时,会有类似 ‘gbk' codec can't decode byte 0xa8 这样的报错。解决办法如下

f = open(file=file,'r',encoding='utf-8',error='ignore')

转载请注明原文地址: https://www.6miu.com/read-2621830.html

最新回复(0)