Python uses split to read the number of each line in the text file and save it to the corresponding folder

import re
from numpy import *
def getStr(file_path,file_path1):
    fp = open(file_path, 'r')
    op = open (file_path1, ' w ' )
     for eachline in fp.readlines ():
        lines = re.split("\t| |\n",eachline)
        print(lines[2:10])
        newlines=lines[2:10]
        i = 0   
        for s in newlines:
            i=i+1
            if i<8:
                print(s)
                op.write(s+',')                        
            elif i==8:
                op.write(s+'\n')
                continue      
            else: 
                break    
    fp.close()
    op.close()

if __name__ == '__main__':
    for i in range(483):
        getStr(str(i)+'.txt','result/'+str(i)+'.txt')

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324782077&siteId=291194637