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?