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
相关推荐
阿俊-全栈开发1 小时前
扩展设计解析:LikeShop Go 版商城营销活动的插件化扩展设计思路干啥啥不行,bug第一名1 小时前
EAFNOSUPPORT、EPROTOTYPE、EOPNOTSUPP:socket 的三层参数没有对齐期货资管源码2 小时前
内盘期货中远期与跨品种套利开发笔记:价差、配对与执行细节我要见SA姐12 小时前
用生活化类比当钥匙,一键打开 C++ 入门大门1024奇点3 小时前
第四篇 第 03 课AI大模型-小雄3 小时前
Codex 如何自动修复项目 Bug?从错误定位到测试验证的实战教程大彼方..3 小时前
CSDN-02-开发环境介绍与安装风月说与山鬼3 小时前
五、python基础——集合、映射类型BK贝壳4 小时前
初始化一亿个全 True 或全 False:bool-hybrid-array 的 TruesArray/FalsesArray 占位构造本机实测编程见习者4 小时前
外卖员招聘助手