title: Python: Script won't find word in text file
body: <p>I am trying to find specific words from a text file, however my script doesn't seem to be able to match the word to what's written on a line in the text file, even though I know it matches. I've noticed there are spaces but since I am saying <code>entry in line</code>, shouldn't it work?</p>
  
  <p>I have also tried:</p>
  
  <pre><code>  if str(entry) in line:, 
    if str(entry) in str(line): and 
    if entry in str(line): 
  </code></pre>
  
  <p>but none of them seem to work either</p>
  
  <p>I can't see where I'm going wrong. Any help would be appreciated.</p>
  
  <p>Here is my code </p>
  
  <pre><code>with open(address+'file_containing_data_I_want.txt') as f:
      for entry in System_data:
          print "Entry:"
          print entry 
          for line in f:
              print "Start of line"
              print line
              print"End of line"
              if entry in line:
                  print "Found entry in line" #This never gets printed
  </code></pre>
  
  <p>Using the print statements (for just the first entry) I see:</p>
  
  <pre><code>Entry:
  Manufacturer
  
  
  Start of line
  ??
  
  End of line
  Start of line
  
  
  End of line
  Start of line
  Manufacturer=manufacturer_data
  
  End of line
  Start of line
  Model=model_data
  
  End of line
  Start of line
  
  
  End of line
  Start of line
  
  
  End of line
  </code></pre>
  
  <p>The text file looks like this (Note:I can't change the text file as this is the way I will be receiving it, <code>'</code> indicates a blank line):</p>
  
  <pre><code>'
  '
  Manufacturer=manufacturer_data
  Model=model_data
  '
  '
  '
  </code></pre>
  
  <p><strong>UPDATE:</strong>
  Changing my script to:</p>
  
  <pre><code>with open(address+'file_containing_data_I_want.txt') as f:
      for line in f:
          print "Start of line %s" % line
          print"End of line" 
          for entry in System_data:
              print "Entry: %s" % entry
              if entry in line.strip():
                  print "Found entry in line"
  </code></pre>
  
  <p>Results in this being printed (Still no "Found entry in line"):</p>
  
  <pre><code>Entry: Manufacturer
  Entry: Model
  Start of line: 
  End of line
  Entry: Manufacturer
  Entry: Model
  Start of line: Manufacturer=manufacturer_data
  End of line
  Entry: Manufacturer
  Entry: Model
  Start of line: Model=model_data
  Entry: Manufacturer
  Entry: Model
  Start of line: 
  End of line
  Entry: Manufacturer
  Entry: Model
  Start of line: 
  End of line
  </code></pre>
  
  <p>Changing my code to this:</p>
  
  <pre><code>for line in f:
      print "Start of line: %s" % line.strip("\r\n")
      print "End of line" 
      for entry in System_data:
          print "Entry: %s" % entry.strip()
          if entry.strip() in line.strip("\r\n"):
              print "FOUND!!!!!!!!!!!!!"
  </code></pre>
  
  <p>Gives me this:</p>
  
  <pre><code>Start of line: ??
  End of line
  Entry: Manufacturer
  Entry: Model
  Start of line: 
  End of line
  Entry: Manufacturer
  Entry: Model
  Start of line: Manufacturer=manufacturer_data
  End of line
  Entry: Manufacturer
  Entry: Model
  Start of line: Model=model_data
  End of line
  </code></pre>