#! /usr/bin/env python #_*_coding:utf-8_*_ ''' Created on 2017-5-12 @author: Win-1 ''' import re,os,time import xlwt #读取SNRt值 def readSNRt(): hotimeList = [] SrcMacList = [] BMacList = [] timeList = [] FileOpen = open('20170521-3015_7_V175.85.log') FileMsg = FileOpen.readlines() for i in range(0,len(FileMsg)): timeShow = re.findall(r'\d*:\d*:\d*:\d*',FileMsg[i]) hotime = re.findall(r'hotime=\d*',FileMsg[i]) SrcMac = re.findall(r'SrcMac=\dx[a-zA-Z0-9-]+',FileMsg[i]) # 需要大小写字母 BMac = re.findall(r'BMac=\dx\d*',FileMsg[i]) # 同上一行 if hotime: timeList.append(''.join(timeShow)[:]) hotimeList.append(''.join(hotime)[7:]) SrcMacList.append(''.join(SrcMac)[7:]) BMacList.append(''.join(BMac)[5:]) return timeList,hotimeList,SrcMacList,BMacList FileOpen.close() def writeSNRtRSSIt(): newTable = '20170522-3021_V175.188.xlsx' wb = xlwt.Workbook(encoding='utf-8') ws = wb.add_sheet('20170522-3021_V175.188',cell_overwrite_ok=True) #创建表 headData = ['Time','hotime','SrcMac','BMac'] for colnum in range(0,4): ws.write(0,colnum,headData[colnum],xlwt.easyxf('font:bold on')) timeShow = items[0] hotime = items[1] SrcMac = items[2] BMac = items[3] index = 1 for i in range(len(hotime)): if int(hotime[i])<50: #提取hotime大于50的值 print 'hotime less 50' continue ws.write(index,0,timeShow[i]) ws.write(index,1,hotime[i]) ws.write(index,2,SrcMac[i]) ws.write(index,3,BMac[i]) index+=1 wb.save(newTable) if __name__ == '__main__': items = readSNRt() writeSNRtRSSIt()