title: How do you split reading a large csv file into evenly-sized chunks in Python?
body: <p>In a basic I had the next process.</p>
  
  <pre><code>import csv
  reader = csv.reader(open('huge_file.csv', 'rb'))
  
  for line in reader:
      process_line(line)
  </code></pre>
  
  <p>See this related <a href="https://stackoverflow.com/questions/312443/how-do-you-split-a-list-into-evenly-sized-chunks-in-python">question</a>. I want to send the process line every 100 rows, to implement batch sharding.</p>
  
  <p>The problem about implementing the related answer is that csv object is unsubscriptable and can not use len.</p>
  
  <pre><code>&gt;&gt;&gt; import csv
  &gt;&gt;&gt; reader = csv.reader(open('dataimport/tests/financial_sample.csv', 'rb'))
  &gt;&gt;&gt; len(reader)
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  TypeError: object of type '_csv.reader' has no len()
  &gt;&gt;&gt; reader[10:]
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  TypeError: '_csv.reader' object is unsubscriptable
  &gt;&gt;&gt; reader[10]
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  TypeError: '_csv.reader' object is unsubscriptable
  </code></pre>
  
  <p>How can I solve this?</p>