零基础第31讲 动动手求助
大佬们求助啊,mac os python 3.8 jupyter notebook,我下载下来的record.txt 如果用textedit 打开的话就是图中这样,我run了一遍参考答案的代码,给我这样的error code请问是我下载的文件问题吗还是我的环境问题?万分感谢!!!
---------------------------------------------------------------------------
UnicodeDecodeError Traceback (most recent call last)
<ipython-input-40-ab374b26e6a4> in <module>
38 f.close()
39
---> 40 split_file('record.txt')
<ipython-input-40-ab374b26e6a4> in split_file(file_name)
21 f = open(file_name)
22
---> 23 for each_line in f:
24 if each_line[:6] != '======':
25 (role, line_spoken) = each_line.split(':', 1)
~/.pyenv/versions/3.8.2/lib/python3.8/codecs.py in decode(self, input, final)
320 # decode input (taking the buffer into account)
321 data = self.buffer + input
--> 322 (result, consumed) = self._buffer_decode(data, self.errors, final)
323 # keep undecoded input until the next call
324 self.buffer = data
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xbf in position 2: invalid start byte
你看看你txt的编码,很显然不是utf-8。所以解码不出来 2269099035 发表于 2020-10-30 13:06
你看看你txt的编码,很显然不是utf-8。所以解码不出来
谢谢!我也觉得是,但是我就是从网页上直接下载的,不明白为啥我下载下来的就是这样orz,请问你有这个文件可以发我一份吗? 编码问题
页:
[1]