title: How to find number of lines in text file using python?
body: <ol>
  <li>i need to get a text file fro given .tst file... and find number of lines in it</li>
  <li>I'm getting 0 as output..</li>
  <li>I Need to execute program twice for getting those text files</li>
  <li>Is there a problem with my code??</li>
  </ol>
  
  
  
  <pre><code>name_of_file = raw_input("tst file address please:")
  
  import re
  f = open(name_of_file+".tst",'r')
  data = f.read()
  y = re.findall(r'Test Case:(.*?)TEST.UNIT:',data,re.DOTALL)
  fb = open('tcases.txt' ,'w' )
  for line in y :
   fb.write(line)
  z = re.findall(r'TEST.SUBPROGRAM:(.*?)TEST.NEW',data,re.DOTALL)
  fc = open('tsubprgs.txt' ,'w' )
  for line in z :
   fc.write(line)
  x = re.findall(r'TEST.UNIT:(.*?)TEST.SUBPROGRAM:',data,re.DOTALL)
  fa = open('tunits.txt' ,'w' )
  for line in x :
   fa.write(line)
  
  with open('tunits.txt') as foo:
   lines = len(foo.readlines())
   print lines
  </code></pre>