python 利用split读取文本文件中每一行的数字并保存至相应文件夹
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')