Background background:
My TXT file contains search terms, because the original query (search term) is used/or, to divide the word, and I want to achieve is each word is a separate line, and write txt
First step: Read TXT file by line
s = []f = open (' Querylist.txt ', ' R ') #由于我使用的pycharm已经设置完了路径, so I wrote the file name for lines in F: # Query_list.append ( Line.replace ('/', '). Replace (', ', '). Replace (","). Strip (' \ n ')) ls = lines.strip (' \ n '). Replace (","). Replace (', ', '/'). Replace ('? ', '). Split ('/') for i in LS: s.append (i) F.close () print (s)
Step two: Write txt on a line-by-row basis
Write each element of the s in our list to Tet, an element is a line, there are many ways, I just list A
(Create an empty txt:query_result in your file path in advance.)
F1 = open (' Query_result.txt ', ' W ') for J in S: f1.write (j+ ' \ n ') F1.close ()
Finally, the result of my output is:
Python reads txt text row by line, writes the TXT in line with the split word