UnicodeDecodeError: 'gbk' codec can't decode byte 0xfd in position 3952: illegal multibyte sequence

使用python读取文件数据时,报错UnicodeDecodeError: 'gbk' codec can't decode byte 0xfd in position 3952: illegal multibyte sequence

dataFile = open('dictionary.txt','r');
for line in dataFile:
    print(line)

尝试了各种方法,最后只用EditPlus工具将dictionary.txt的编码格式改为UTF-8,并加入代码encoding='utf-8',问题得以解决。

dataFile = open('dictionary.txt','r',encoding='utf-8');
for line in dataFile:
    print(line)

你可能感兴趣的:(UnicodeDecodeError: 'gbk' codec can't decode byte 0xfd in position 3952: illegal multibyte sequence)