#将一个文件分割成固定行的小文件
import os import sys num = 0 fnum = 0 path = sys.argv[1] fname = ‘data-%d‘ % fnum fw = open(fname,‘w‘) for t in os.listdir(path): filename = os.path.join(path,t) fd = open(filename) for line in fd: line = line.strip() num = num + 1 if line: if num > 10000000: num = 0 fw.close() fnum = fnum + 1 fname = ‘data-%d‘ % fnum fw = open(fname,‘w‘) fw.write(line + ‘\n‘) fw.close()
原文:http://www.cnblogs.com/iamlehaha/p/6618847.html