关于中文的文本,读取总是会失败
Traceback (most recent call last):
File "F:代码python学习练习py_study hree.py", line 3, in <module>
txt = open("三国演义.txt", "r", encoding='utf-8').read()
File "C:Pythonlibcodecs.py", line 321, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa1 in position 0: invalid start byte
出现这段报错。
这时候只需要将TXT文件另存为,编码方式改为‘utf-8’即可