1,测试一千次开关机,几个阶段的时间
# coding:utf-8 import os from datetime import datetime def get_txts(file_path): files = os.listdir(file_path) for file in files: with open(os.path.join(file_path, file), "r", encoding="UTF-8") as f: for txt in f: if 'start power on' in txt: t1 = txt[0:19].replace('_', '-') t11 = txt t111 = datetime.strptime(t1, '%Y-%m-%d %H:%M:%S').timestamp() if 'vinput: window position has been updated to: [0,0]' in txt: t2 = txt[0:19].replace('_', '-') t22 = txt t222 = datetime.strptime(t2, '%Y-%m-%d %H:%M:%S').timestamp() if 'Startup complete' in txt: t3 = txt[0:19].replace('_', '-') t33 = txt t333 = datetime.strptime(t3, '%Y-%m-%d %H:%M:%S').timestamp() print(t222 - t111, '|', t333 - t111) if t222 - t111 > 15 or t333 - t111 > 50: print('file = ', file) get_txts(r'E:\Work\space\raspberry_log\logdate\常温(1)\常温\log')View Code
标签:-%,便捷,程序,同事,datetime,file,t111,path,txt From: https://www.cnblogs.com/147258llj/p/17970793