问题探究
实现代码
f=open("niu.txt")
interviewer=[]
Qtum=[]
count=1
for each_line in f:
if each_line[:6]!="******":
(role,line_spoken)=each_line.split(":",1) #字符串分割操作,默认以空格切片,1是取右边
if role =="提问":
interviewer.append(line_spoken)
if role =="帅初":
Qtum.append(line_spoken)
else: #文件的分别操作
file_name_interviewer="interviewer_"+str(count)+".txt"
file_name_Qtum="Qtum_"+str(count)+".txt"
interviewer_file=open(file_name_interviewer,"w")
Qtum_file=open(file_name_Qtum,"w")
interviewer_file.writelines(interviewer)
Qtum_file.writelines(Qtum)
interviewer_file.close()
Qtum_file.close()
interviewer=[]
Qtum=[]
count += 1
f.close()