f= open('duihua.txt',encoding='utf-8')
heike=[]
xiaobai=[]
count=1
for each_line in f:
if each_line[:6] != '======':
(role,line_spoken) = each_line.split(':',1)
if role=='heike':
heike.append(line_spoken)
if role=='xiaobai':
xiaobai.append(line_spoken)
else:
file_name_heike='heike'+str(count)+'.txt'
file_name_xiaobai='xiaobai'+str(count)+'.txt'
heike_file=open(file_name_heike,'w')
xiaobai_file=open(file_name_xiaobai,'w')
heike_file.writelines(heike)
xiaobai_file.writelines(xiaobai)
heike_file.close()
xiaobai_file.close()
heike=[]
xiaobai=[]
count+=1
f.close()
|