import os
hesay=[]
hersay=[]
count=1
f= open("D://python3pra/textfield.txt")
for spoke_line in f :
print(spoke_line)
if(spoke_line[:6]!="======"):
(role,speak) = spoke_line.split(':',1)
if(role=="他说"):
hesay.append(speak)
else:
hersay.append(speak)
else:
he_file_name="hesaid"+str(count)+".txt"
her_file_name="hersaid"+str(count)+".txt"
hefile= open(he_file_name,'w')
herfile =open(her_file_name,'w')
hefile.writelines(hesay)
herfile.writelines(hersay)
hefile.close()
herfile.close()
hesay=[]
hersay=[]
count+&
python3读取文本文件分开写入
最新推荐文章于 2020-10-28 20:41:56 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)