title: Mixing files and loops
body: <p>I'm writing a script that logs errors from another program and restarts the program where it left off when it encounters an error. For whatever reasons, the developers of this program didn't feel it necessary to put this functionality into their program by default.</p>
  
  <p>Anyways, the program takes an input file, parses it, and creates an output file. The input file is in a specific format:</p>
  
  <pre class="lang-none prettyprint-override"><code>UI - 26474845
  TI - the title (can be any number of lines)
  AB - the abstract (can also be any number of lines)
  </code></pre>
  
  <p>When the program throws an error, it gives you the reference information you need to track the error - namely, the UI, which section (title or abstract), and the line number relative to the beginning of the title or abstract. I want to log the offending sentences from the input file with a function that takes the reference number and the file, finds the sentence, and logs it. The best way I could think of doing it involves moving forward through the file a specific number of times (namely, n times, where n is the line number relative to the beginning of the seciton). The way that seemed to make sense to do this is:</p>
  
  <pre><code>i = 1
  while i &lt;= lineNumber:
      print original.readline()
      i += 1
  </code></pre>
  
  <p>I don't see how this would make me lose data, but Python thinks it would, and says <code>ValueError: Mixing iteration and read methods would lose data</code>. Does anyone know how to do this properly?</p>