D:\Python\python.exe D:/Python_Item/实验/实验六.py
Traceback (most recent call last):
File "D:/Python_Item/实验/实验六.py", line 8, in <module>
print(f.read())
File "D:\Python\lib\codecs.py", line 321, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x90 in position 17: invalid start byte
代码如下:
#!/usr/bin/env Python
# _*_coding:utf-8_*_
#第一步:打开文件
f = open('F:\轩辕\大数据材料\轩辕大数据实验室建设\实验体系\测试.docx','r',encoding = 'utf-8')
#第二步:读取文件内容
print(f.read())
#第三步:关联文件
f.close()
2 个解决方案
#1
[试过txt文件读取没问题,
http://blog.csdn.net/qianchenglenger/article/details/51582005]