读取txt文件报错:UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc8 in position 0

时间:2023-01-04 21:39:24

python在open读取txt文件时,出现UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc8 in position 0: invalid continuation byte报错

解决办法有二:

①把编码方式utf-8 修改为gb18030

②把原来的txt文件重新打开另存为的时候,把编码方式修改为utf-8,然后代码的encoding=‘utf-8’保持不变即可

读取txt文件报错:UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc8 in position 0