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
相关推荐
lilihuigz8 分钟前
Meta Box完整指南:WordPress自定义字段与内容框架高效构建结构化内容 - 易服客工作室xxie12379414 分钟前
Python 闭包的调用方法与实践HZZD_HZZD14 分钟前
用电行为异常检测VAE-基于PyTorch设计用电行为异常检测模型:从时序特征提取到变分自编码器部署的完整实战aini_lovee16 分钟前
计算 HOG算子的典型 MATLAB 程序楷哥爱开发17 分钟前
降低网络爬虫成本:基础设施优化指南思-无-涯26 分钟前
AI Agent技能编写与质量保障feifeigo1231 小时前
matlab电力系统重构实现小c君tt1 小时前
QT笔记记录布朗克1681 小时前
Go 入门到精通-08-复合类型之数组与切片2601_956319881 小时前
2026年下半年AI量化学习,分清表达开发和验证