python读取包含中文的文件报错:UnicodeDecodeError: ‘gbk’ codec can’t decode byte 0xaf in position 64: illegal multibyte sequence
解决方法:打开文件时添加 encoding=’utf-8’ 进行编码即可
原程序:
with open('test.txt','r') as file:
file=file.readlines()
print(file)
for i in file:
print(i)
break
修改后:
with open('test.txt','r',encoding='utf-8') as file:
file=file.readlines()
print(file)
for i in file:
print(i)
break