title: Trying to stepwise iterate through 2 files in python
body: <p>I am trying to merge two LARGE input files together into 1 output, sorting as I go. </p>
  
  <pre><code>## Above I counted the number of lines in each table
  
  print("Processing Table Lines: table 1 has " + str(count1) + " and table 2 has " + str(count2) )
  newLine, compare, line1, line2 = [], 0, [], []
  
  while count1 + count2 &gt; 0:
      if count1 &gt; 0 and compare &lt;= 0: count1, line1 = count1 - 1, ifh1.readline().rstrip().split('\t')
      else: line1 = []
      if count2 &gt; 0 and compare &gt;= 0: count2, line2 = count2 - 1, ifh2.readline().rstrip().split('\t')
      else: line2 = []
  
      compare = compareTableLines( line1, line2 )
      newLine = mergeLines( line1, line2, compare, tIndexes )
  
      ofh.write('\t'.join( newLine + '\n'))
  </code></pre>
  
  <p>What I expect to happen is that as lines are written to output, I pull the next line in the file I used to be read in if available.  I also expect that the loop cuts out once both files are empty.</p>
  
  <p>However I keep getting this error:
      ValueError: Mixing iteration and read methods would lose data</p>
  
  <p>I just don't see how to get around it.  Either file is too large to keep in memory so I want to read as I go.</p>