title: python - if statement and list index outside of range
body: <p>I have a csv file with a 1st part made up of 3 entries and 2nd part made up of 2 entries. I want to isolate the data made up of 3 entries.</p>
  
  <p>i wrote the following:</p>
  
  <pre><code>filename=open("datafile.txt","r")
  data_3_entries_list=[]
  
   for line in filename:
      fields=line.split(",")
      if fields[2] == 0:
          break
      else:
          data_3_entries_list.extend(line)
  </code></pre>
  
  <p>i get the error message:<br>
  if fields[2] == 0 :
  IndexError: list index out of range
       print(data_3_entries_list)</p>
  
  <p>I also tried with if fields[2] is None but i get the same error.
  I dont understand why im getting this error?</p>