我有文件包含
"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"
我只在文件中寻找第二行,但来自此代码的输出是 1 行也显示