NLP:两种方法(自定义函数和封装函数)实现提取两人对话内容(***分隔txt文档),并各自保存为txt文档
生活随笔
收集整理的這篇文章主要介紹了
NLP:两种方法(自定义函数和封装函数)实现提取两人对话内容(***分隔txt文档),并各自保存为txt文档
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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文檔
?
?
總結
以上是生活随笔為你收集整理的NLP:两种方法(自定义函数和封装函数)实现提取两人对话内容(***分隔txt文档),并各自保存为txt文档的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 成功解决Your CPU support
- 下一篇: VM之Linux:Linux的Ubunt