title: Check if a line exists in a file
body: <p>How can I check if a line exists in a file?</p>
  <p>I'd also like to write the line to the file if it does not exist.</p>
  <p>This is my current attempt:</p>
  <pre><code>logfile = open('ip.log', 'a+')
  
  while 1:
      line = logfile.readline()
      #line.replace(&quot;\n&quot;, &quot;&quot;)
      print line
          
      if line == str(self.CLIENT_HOST):
          print &quot;Line Found Skipping&quot;
      else:
          logfile.write(str(self.CLIENT_HOST)+&quot;\n&quot;)
      if not line:
          print &quot;EOF Reached&quot;
          break
      print line
  logfile.close()
  </code></pre>