title: How to set the "chunk size" of read lines from file read with Python subprocess.Popen() or open()?
body: <p>I have a fairly large text file which I would like to run in chunks. In order to do this with the <code>subprocess</code> library, one would execute following shell command:</p>
  
  <pre><code>"cat hugefile.log"
  </code></pre>
  
  <p>with the code:</p>
  
  <pre><code>import subprocess
  task = subprocess.Popen("cat hugefile.log", shell=True,  stdout=subprocess.PIPE)
  data = task.stdout.read()
  </code></pre>
  
  <p>Using <code>print(data)</code> will spit out the entire contents of the file at once. How can I present the number of chunks, and then access the contents of this file by the chunk size (e.g. chunk = three lines at a time). </p>
  
  <p>It must be something like: </p>
  
  <pre><code>chunksize = 1000   # break up hugefile.log into 1000 chunks
  
  for chunk in data:
      print(chunk)
  </code></pre>
  
  <p>The equivalent question with Python <code>open()</code> of course uses the code</p>
  
  <pre><code>with open('hugefile.log', 'r') as f:
       read_data = f.read()
  </code></pre>
  
  <p>How would you <code>read_data</code> in chunks? </p>