读文件出现编码错误

问题:读文件出现编码错误
UnicodeDecodeError: ‘gbk’ codec can’t decode byte 0xbf in position 2: illegal multibyte sequence
方法:
指定编码格式,忽略错误

open('a.txt',encoding='uft-8')


file = open('a.txt', encoding='gbk')


file = open('a.txt', encoding='gb18030')

【读文件出现编码错误】
file = open('a.txt', encoding='gb18030', errors='ignore')

    推荐阅读