在使用python3.4读取文件时,我先使用encoding=utf-8进行编码,
但是会出现:UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf5 in position 15: invalid start byte
后面使用encoing=gbk编码,又会出现:UnicodeDecodeError: 'gbk' codec can't decode byte 0xf5 in position 15: illegal multibyte sequence
我的代码如下:
file=open('C:/Users/Administrator/Desktop/x.csv','r',encoding='gbk')
data=file.readline()
print(data)
后来我使用了rb读取方式,文件能够打开,返回的结果乱码:
b'PK\x03\x04\x14\x00\x06\x00\x08\x00\x00\x00!\x00J\xf5%\xd1\x86\x01\x00\x00\x91\x06\x00\x00\x13\x00\x08\x02[Content_Types].xml
但尝试encode之后,还是不行。这是为什么呢?
你这个应该不是csv文件,是不是xlsx文件格式?