回顾了以下视频,修改了一些小问题。import pickle
def dump(count,boy,girl):
boy_file = open('boy_'+count+'.txt','w',encoding='utf-8')
girl_file = open('girl_'+count+'.txt','w',encoding='utf-8')
pickle.dump(boy,boy_file)
pickle.dump(girl,girl_file)
'boy_'+count+'.txt'.close()
'girl_'+count+'.txt'.close()
count += 1
def split(file):
count = 1
boy = []
girl = []
for each in file:
if '====' not in each:
(name,spoken) = each.split(':',1)
if name == '小甲鱼':
boy.append(spoken)
elif name == '小客服':
girl.append(spoken)
else:
dump(count,boy,girl)
boy = []
girl = []
dump(count,boy,girl)
file.close()
file = open('record.txt','r',encoding='utf-8')
split(file)
报错代码:Traceback (most recent call last):
File "D:/编程练习/课后作业(永久储存,第31讲,动动手第0题).py", line 33, in <module>
split(file)
File "D:/编程练习/课后作业(永久储存,第31讲,动动手第0题).py", line 17, in split
for each in file:
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38-32\lib\codecs.py", line 322, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xbf in position 2: invalid start byte
|