for i, g in enumerate(grouper(n, f, fillvalue=''), 1):
    with open('small_file_{0}'.format(i * n), 'w') as fout:
        fout.writelines(g)
Splitting large text file into smaller text files by line numbers using Python