Python 过滤a文件中每一行内容,保存到b文件中
#coding=utf-8
print 1
#初始化文件crash_log.log
with open('e:/1/crash_log.log','w')as f: f.close()
def fw(self): print 2 with open('e:/1/monkey_log.txt','r')as f1 , open('e:/1/crash_log.log','a+') as f2:
#设置循环读取每一行,判断过滤 while True: line=f1.readline() if '// Monkey finished' in line: break f2.close() elif '// CRASH:' in line : f2.write(line+ '\n') elif '// Short Msg:' in line: f2.write(line+ '\n') elif '// Long Msg:' in line: f2.write(line+ '\n'+'\n'+'\n') #else: #continue if __name__ == "__main__": fw(1)