Policy Information
NLP:两种方法(自定义函数和封装函数)实现提取两人对话内容(***分隔txt文档),并各自保存为txt文档
目录
- 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()
相关文章
Python:两种方法(自定义函数和封装函数)实现提取两人对话内容(***分隔txt文档),并各自保存为txt文档
评论