def gen_chunks(reader, chunksize=100):
    """ 
    Chunk generator. Take a CSV `reader` and yield
    `chunksize` sized slices. 
    """
chunk = []
for i, line in enumerate(reader):
    if i % chunksize == 0 and i > 0:
        yield chunk
del chunk[:]
chunk.append(line)
yield chunk
for chunk in gen_chunks(reader):
    print(chunk)
for chunk in gen_chunks(list(range(10)), chunksize=3):
    pass
How do you split a csv file into evenly sized chunks in Python?