第四部:
python 文件修改如下:
f=open('record.txt', encoding='utf-8')
boy=[]
girl=[]
count=1
for each in f:
if each[:6]!='======':
(role,spoken)=each.split(":",1)
if role=='小甲鱼':
boy.append(spoken)
if role=='小客服':
girl.append(spoken)
else:
file_name_boy='boy'+str(count)+'.txt'
file_name_girl='girl'+str(count)+'.txt'
boy_file=open(file_name_boy,'x', encoding='utf-8')
girl_file=open(file_name_girl,'x', encoding='utf-8')
boy_file.writelines(boy)
girl_file.writelines(girl)
boy_file.close()
girl_file.close()
boy=[]
girl=[]
count+=1
file_name_boy='boy'+str(count)+'.txt'
file_name_girl='girl'+str(count)+'.txt'
boy_file=open(file_name_boy,'x', encoding='utf-8')
girl_file=open(file_name_girl,'x', encoding='utf-8')
boy_file.writelines(boy)
girl_file.writelines(girl)
boy_file.close()
girl_file.close()
f.close()
|