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
相关推荐
知识分享小能手12 分钟前
Flask入门学习教程,从入门到精通,Flask智能租房——前期准备 知识点详解(5)Curvatureflight16 分钟前
【架构实战】生产级大模型 API 接入指南:流式响应(Streaming)异常处理与监控闭环smj2302_796826521 小时前
解决leetcode第3943题递增后的数对数量এ慕ོ冬℘゜1 小时前
JS 前端基础面试题浩少7021 小时前
【无标题】deepin_sir1 小时前
06 Chroma_持久化与生产环境部署实战nnsix2 小时前
C# 字符串 根据换行符分割Vallelonga2 小时前
Rust Conversion 工具 trait AsRef AsMutVallelonga2 小时前
Rust 中的“解引用”和智能指针与 MutexGuard 等小鱼仙官2 小时前
Windonws 视频存储,10s/不限时