How to find the exact length and matched string in a file using python
<p>I have file contains </p>

<pre><code>"Starting program and 
Starting program
Loading molecule...
Initialising variables...
Starting the calculation - this could take a while!
Molecule energy = 2432.6 kcal mol-1
Calculation finished. Bye!"
import sys
import re

search_string = "Starting program"
txtlength=len(search_string)
print "txtlength",txtlength
lines = open( "C:\search.txt", "r" ).readlines()
for line in lines:
    if re.search( search_string, line ):
        print line,

    else :
        print "Not found"
</code></pre>

<p>I am looking for only 2nd line in the file but ouput coming from this code is 1 line is also displaying</p>
