怎么解决这个error
file = open('/Users/yedaoguang/Desktop/lessonpy/OpenMe.mp3')for each_line in file:
print(each_line, end='')
file.close()运行出错显示
Traceback (most recent call last):
File "/Users/yedaoguang/Desktop/lessonpy/readfile.py", line 2, in <module>
for each_line in file:
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/codecs.py", line 322, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb3 in position 0: invalid start byte
这个我应该怎么改code
"OpenMe.mp3" 是个文本文件,之所以出错是因为其中包含有中文字符。
改成下面这样就可以了:
file = open('/Users/yedaoguang/Desktop/lessonpy/OpenMe.mp3' , "rt" , encoding = "cp936")
for each_line in file:
print(each_line, end='')
file.close()
用记事本打开 openme.mp3 另存为,然后选编码为ansi保存
页:
[1]