python 将TXT拆分每个5万行
< 返回列表时间: 2020-08-06来源:OSCHINA
import time import hashlib filtpath="test.txt" with open(filtpath, "r") as f: print(time.strftime('%Y-%m-%d %H:%M:%S') + " 开始..." + filtpath) line_num = 0 file_num = 1 for line in f.readlines(): line = line.strip('\n') #去掉列表中每一个元素的换行符 #print(line) line_num += 1 if line_num % 50000 == 0 : file_num += 1 print(file_num) with open( filtpath[0:-4]+ '_'+ str(file_num) + '.txt','a') as file_handle: file_handle.write(line) file_handle.write('\n') print("line_num=" + str(line_num)) print(time.strftime('%Y-%m-%d %H:%M:%S') + " 结束..." + filtpath)
热门排行