title: Grep and Python
body: <p>I need a way of searching a file using grep via a regular expression from the Unix command line. For example when I type in the command line:</p>
  
  <pre><code>python pythonfile.py 'RE' 'file-to-be-searched'
  </code></pre>
  
  <p>I need the regular expression <code>'RE'</code> to be searched in the file and print out the matching lines.</p>
  
  <p>Here's the code I have:</p>
  
  <pre><code>import re
  import sys
  
  search_term = sys.argv[1]
  f = sys.argv[2]
  
  for line in open(f, 'r'):
      if re.search(search_term, line):
          print line,
          if line == None:
              print 'no matches found'
  </code></pre>
  
  <p>But when I enter a word which isn't present, <code>no matches found</code> doesn't print</p>