title: Batch files runs over half only?
body: <p>I have come across this puzzling problem in Python, where I am running this script to iterate over files and pull out the line with the highest value in index position 6. For some reason, when I run this, it only iterates over about half the files only.</p>
  
  <p>This is the code:</p>
  
  <pre><code>output=open("max.txt","w")
  
  from glob import glob
  for filename in glob("*bam.txt"):
      file=open(filename,"r")
      lines = file.readlines()
      max=0   
  
      for i in range(0,len(lines)+1): 
          if i&lt;len(lines):
              newlines=lines[i].replace("\n","\t")
              splitted=newlines.split("\t")
              if int(splitted[6])&gt;int(max):
                  max=splitted[6]
                  index=i
          elif i==len(lines):
              output.write(filename+"\t"+lines[index])
          else:
              print("There is an error!")
  
  output.close()
  </code></pre>
  
  <p>And this is an error message I receive at the end:</p>
  
  <pre><code>Traceback (most recent call last):
    File "&lt;stdin&gt;", line 15, in &lt;module&gt;
  IndexError: list index out of range
  </code></pre>
  
  <p>I specifically have <code>len(lines)+1</code> as the end of my range because I know it would be excluded and if I only had <code>len(lines)</code>, then <code>i</code> would never equal <code>len(lines)</code> and thus nothing would be written to output.</p>
  
  <p>Many thanks!</p>