title: Python cannot find string in file when the string is just there
body: <p>I have a database file "db.txt" in the format as follows:</p>
  
  <pre><code>"sg_number":1,"blablabala"....
  "sg_number":2,"blablabala"....
  "sg_number":10,"blablabala"....
  "sg_number":9,"blablabala"....
  </code></pre>
  
  <p>and so on.</p>
  
  <p>I want to delete all the lines that contains '"sg_number": i', for i in the range (1, 8) and output the remaining lines to another file "db_filtered.txt"</p>
  
  <p>So I wrote the following code:</p>
  
  <pre><code>infile = open("db.txt", "r")
  
  newopen = open('db_filtered.txt', 'w')
  
  for i in range(1,8):
      a='"sg_number":'+ str(i) + ','
      for line in infile :
          if a in line:
              line = line.replace('.' , '')
          else:
              newopen.write(line)
  
  newopen.close()
  </code></pre>
  
  <p>However, the generated db_filtered.txt still has everything in the db.txt. What I am expecting is for lines with "sg_number" less than 9 to be deleted.</p>
  
  <p>What I noticed is that removing the "+ ','" in line 6 leads to deletion of any line that contains "sg_number":1 , which is line 1 and 3. But line 2 which satisfies the condition "i in range(1, 8)" is not deleted.</p>
  
  <p>May I know what is wrong here and what corrections I should make for the code to do what it is supposed to do?</p>
  
  <p>Thanks a lot!</p>