I have some trouble trying to split large files (say, around 10GB). The basic idea is simply read the lines, and group every, say 40000 lines into one file. But there are tw
chunk_size = 40000 fout = None for (i, line) in enumerate(fileinput.FileInput(filename)): if i % chunk_size == 0: if fout: fout.close() fout = open('output%d.txt' % (i/chunk_size), 'w') fout.write(line) fout.close()