def readfiletoexcel():
wb = xlwt.Workbook()
sheet = wb.add_sheet('端口信息')
#['Interface', 'PHY', 'Protocol', 'InUti', 'OutUti', 'inErrors', 'outErrors']
sheet.write(0,0,'Interface')
sheet.write(0,1,'PHY')
sheet.write(0,2,'Protocol')
sheet.write(0,3,'InUti')
sheet.write(0,4,'OutUti')
sheet.write(0,5,'inErrors')
sheet.write(0,6,'outErrors')
f = open("interface.txt", "r", encoding='utf-8')
lines = f.readlines()
result = "".join(lines)
res = result.split("\n")
j=0
for i in range(0,len(res)):
if len(re.findall(r'Interface',res[i]))>0:
j = i
regex = re.compile(r'GE.+\s+.+\s+.+\s+.+\s+.+\s+.+\s+.+',re.S)
if len(re.findall(regex, res[i])) > 0:
str = re.split('\s+',res[i])
print(str)
sheet.write(i-j,0,str[0])
sheet.write(i-j,1,str[1])
sheet.write(i-j,2,str[2])
sheet.write(i-j,3,str[3])
sheet.write(i-j,4,str[4])
sheet.write(i-j,5,str[5])
sheet.write(i-j,6,str[6])
wb.save("result.xls")
readfiletoexcel()
python往excel中写端口信息
Guaiacum_2024-10-12 23:13
相关推荐
两点王爷3 小时前
Java 面试高频:JWT、Cookie、Session、Token 鉴权详解AI创界者4 小时前
Python 进阶实战(七十三章):Python AI/LLM 应用工程化、流式响应与调用韧性实战微笑星河q5 小时前
C++高阶之【多态】青少儿编程课堂8 小时前
第十八届蓝桥杯青少组图形化真题:校园分形雪花绘制解析(全国青少年信息素养大赛·电子学会图形化考级冲刺)Wellijohn8 小时前
Python 异常到底多贵?我把 try、raise、traceback 的账单逐项拆开测了一遍ClkLog-开源埋点用户分析8 小时前
【产品说明】【埋点分析】ClkLog 商业版 Java 运行环境安全更新说明Dmz丶9 小时前
前端转 AI 100 天 Day 55:RAG 项目实战(四)——前端完善,做一个能用的产品yuzhiboyouye9 小时前
《阿里巴巴 Java 开发手册》的 MySQL 核心规范郝学胜-神的一滴9 小时前
Effective STL 条款12:对容器线程安全性的现实期望