title: List index out of range when reading a file
body: <p>I am opening a file and trying to read the 3rd value on each line. Here is my code </p>
  
  <pre><code>myfile = 'dummy2.pepmasses'
  fileObj = open(myfile, 'r')
  
  
  line = fileObj.readline()
  while line:
      line = fileObj.readline()
      linesplit = line.split()
      weight = linesplit[2]
      print(weight)
  fileObj.close
  </code></pre>
  
  <p>This is resulting the third value being correctly displayed however there is an index error at the bottom but I'm not sure why as I'm not specifying a range of values to read, but rather just to read everything. I believe the issue is that when I read the file there is a blank [] at the bottom, although there are no blank lines on the actual file so I don't understand what is happening. </p>
  
  <p>Any ideas appreciated, thanks. </p>
  
  <p>The end of my file is </p>
  
  <pre><code>STE50,YCL032W            36    1262.6920  0 0 QQGLHPAIMLR
  STE50,YCL032W            37     174.1117  0 0 R
  STE50,YCL032W            38     174.1117  0 0 R
  STE50,YCL032W            39    2081.8783  0 0 GDFEEVAMMNGSDNVTPGGR
  STE50,YCL032W            40     131.0947  0 0 L*
  </code></pre>
  
  <p>The error generated is </p>
  
  <pre><code>174.1117
  2081.8783
  131.0947
  Traceback (most recent call last):
  File "C:/Users/user/PycharmProjects/Test/Test.py", line 12, in &lt;module&gt;
  weight = linesplit[2]
  IndexError: list index out of range
  </code></pre>