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
相关推荐
天天进步201526 分钟前
Python全栈项目--基于机器学习的异常检测系统xxie1237948 小时前
return与print秋98 小时前
从 Python 后端工程师转型 AI Engineer(AI 工程化)的完整补课清单(2026实战版)程序员二叉8 小时前
【Java】 异常高频面试题精讲 | 易错点+对比总结慕木沐9 小时前
Google ADK Java 1.0版本 核心机制与实战 DemoTbisnic9 小时前
AI大模型学习第十一天:技术选型、安全防护与金融实战Roann_seo%9 小时前
C++文件操作完全指南:从文本读写到二进制文件处理hboot9 小时前
AI工程师第一课 - Pythonhuangdong_10 小时前
淘宝商品SKU图自动分类技术深度解析:从DOM解析到智能归档阿正的梦工坊10 小时前
【Rust】12-借用检查器与非词法生命周期