import fileinput
import sysimport re
pattern = "\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}"
filePath = r"C:\seeUthere_errors.log"
for eachline in fileinput.input(filePath):
m = re.search(pattern, eachline)
if m:
sys.stdout.write("==>> ")
sys.stdout.write(eachline)
还可以使用 fileinput模块获得当前行的元信息 (meta information). 其中包括 isfirstline, filename, lineno