郭书宇 发表于 2020-4-4 23:43:45

028课后作业我无法在jupyter notebook完成这个操作

f = open('OpenMe.mp3')
for each_line in f:
        print(each_line,end='')

       
Traceback (most recent call last):
File "<pyshell#8>", line 1, in <module>
    for each_line in f:
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

ba21 发表于 2020-4-4 23:48:24

open("tst.txt", "r", encoding ='utf-8')

xiangjianshinan 发表于 2020-4-4 23:56:10

试试看:

f = open('OpenMe.mp3','rb')
for each_line in f:
      print(each_line,end='')

txxcat 发表于 2020-4-5 00:08:48

试试:
f = open('OpenMe.mp3',encoding='cp936')
或者:
f = open('OpenMe.mp3',encoding='ansi')

zltzlt 发表于 2020-4-5 08:13:11

f = open('OpenMe.mp3', encoding="utf-8")
for each_line in f:
      print(each_line,end='')

参考:https://fishc.com.cn/thread-158932-1-1.html

会计的会怎么念 发表于 2020-4-5 10:58:51

不认识的错误代码,粘下来百度。
你这个是编码错误,
- 小甲鱼的Python 标准异常总结[https://fishc.com.cn/thread-45814-1-1.html]
- 小甲鱼也有关于编码问题和文件打开方法的帖子,想看自己搜索一下吧。

郭书宇 发表于 2020-4-10 14:21:28

txxcat 发表于 2020-4-5 00:08
试试:

或者:

都好像没有这个

郭书宇 发表于 2020-4-10 14:22:13

zltzlt 发表于 2020-4-5 08:13
参考:https://fishc.com.cn/thread-158932-1-1.html

可不行还是打不开的

郭书宇 发表于 2020-4-10 14:25:36

ba21 发表于 2020-4-4 23:48
open("tst.txt", "r", encoding ='utf-8')

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb3 in position 0: invalid start byte
不行还是这个报错

郭书宇 发表于 2020-4-10 14:26:13

xiangjianshinan 发表于 2020-4-4 23:56
试试看:

f = open('OpenMe.mp3','rb')


可这个打开是2进制不是汉字啊

郭书宇 发表于 2020-4-10 14:26:46

会计的会怎么念 发表于 2020-4-5 10:58
不认识的错误代码,粘下来百度。
你这个是编码错误,
- 小甲鱼的Python 标准异常总结

好我会去查查

txxcat 发表于 2020-4-10 14:44:34

郭书宇 发表于 2020-4-10 14:21
都好像没有这个

有什么错误提示?
页: [1]
查看完整版本: 028课后作业我无法在jupyter notebook完成这个操作