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
相关推荐
sharemylove1 小时前
Java集合框架全面详解FYKJ_20101 小时前
springboot众创项目团队管理系统94666-计算机课程设计、毕业设计摇滚侠3 小时前
《On Java 中文版 基础卷》阅读笔记 内部类 20维爱智VR认知学能5 小时前
VR学能软件离线断线与乱序事件测试:确定性到达表与重放郝学胜-神的一滴5 小时前
Effective Python 条款43:自定义容器类Thanks_ks6 小时前
SQL 注入是怎么发生的:从拼接 SQL 讲到预编译语句的防御原理好焊孙辉6 小时前
一条产线省下 30 个电机位:Z 轴和 R 轴,该合成一个了布莱克6056 小时前
Swift 中的逃逸闭包与非逃逸闭包:@escaping 到底在做什么郝学胜-神的一滴7 小时前
Effective STL 条款 14:用扩容函数避免重新分配吃我一窝jio7 小时前
Java IO流核心分类与应用