title: Don't understand why getting 'ValueError: Mixing iteration and read methods would lose data'
body: <p>I'm trying to parse through a file and extract certain terms from that file but it keeps giving me this error and I can't figure out how to fix it so that it works. The code I have so far: </p>
  
  <pre><code>def extract(processFile, extractFile, file):
  print("Extracting data from %s ..." % extractFile)
  
  g = open(extractFile, "w+")
  
  sentence = "";
  count = 0; #Count number of lines extracted
  
  with open(file, 'r') as f:
  #for i in range(0,108084):
      for lines in iter(f):
          #Break down every line read from cacm.all
          line = lines.split()
  
          #If the length of a line is 0 than it reached the end of the file
          if(len(line) == 0):
              break;
  
          #Initialize the first word of the line being processed
          word = line[0]
  
  
          #Case 1, the line starts with .T so it must be the title
          if(word == ".T"):
              sentence = "" #the sentence will be the total title compiled into one string
  
              while(1): #Continue to parse through every line following .T
                  line = f.readline().split()
                  word = line[0]
  
                  if((word == ".B") | (word == ".A") | (word == ".N")| (word == ".X") | (word == ".W") | (word == ".K") | (word == ".C")):
                      break;
                  elif((".W" != word) &amp; (".B" != word) &amp; (".A" != word) &amp; (".N" != word) &amp; (".X" != word) &amp; (".I" != word) &amp; (".K" != word) &amp; (".C" != word)):
                      sentence =  sentence + ' '.join(map(str, line)) + " "
                      continue;
  
              count += 1
              #Construct a line &lt;Type of Data&gt; &lt;Line Count&gt; &lt;Sentence&gt;
              sentence = "I " + str(count) + " " + sentence + "\n"
              g.write(sentence)
  
              #print(count) #Checks the total amount of titles found
              sentence = "" #Reset the sentence
  </code></pre>
  
  <p>It keeps giving me the error which is in the title. Any suggestions to what the problem might be? </p>