import re ##判断行是否存在
def get_need_line(): ## 获取有用信息行 with open('task.log',mode="r") as f: for line in f.readlines(): TaskName = re.search("TaskName", line) ##查询是否存在TaskName state = re.search("Scheduled Task State: ", line)
if TaskName: ##若是TaskName存在,进行其他的操作
file1 = open('Task_name.txt','a+')
line1=line.split(':')[1].lstrip()
#line1=line.split(':')
file1.writelines(line1)
file1.close()
if run_result:
file2 = open('Last_result.txt','a+')
line2=line.split(':')[1].lstrip()
#line2=line.split(':')
file2.writelines(line2)
file2.close()