Python在读文件时:
源码如下:
f = open('C:\\Users\\34682\\Desktop\\test.txt', 'r')
print(f.read())
输出报错:
Traceback (most recent call last):
File "D:/python_yuC/字典", line 6, in <module>
print(f.read())
UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 26: illegal multibyte sequence
报错内容中文翻译:
“gbk”编解码器无法解码位置26中的字节0x80:非法的多字节序列
解决方案:
在open()里面添加encoding = ''UTF-8”
f = open('C:\\Users\\34682\\Desktop\\test.txt', 'r', encoding='UTF-8')
print(f.read())