#查询文件中含有特殊字符串的行 #!/usr/bin/python # -*- coding:utf- -*- import re file1 = open('test.txt','r+') istxt = re.compile(r'.*if.*',re.I) for line in file1.readlines(): line = line.strip() ifstr = re.findall(istxt,line) if ifstr: print ifstr #删除特定行(创建新文件,把不