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
相关推荐
ShineWinsu1 小时前
对于Qt:QFormLayout常见属性以及方法的解析Thanks_ks1 小时前
Python 的垃圾回收——引用计数撑起日常,分代回收收拾残局CyrusYiVPP2 小时前
实测 uv 0.13.7:同一套包,pip 装 94 秒,它只用 19 秒yiangL_2 小时前
Python 学习笔记:递归、turtle绘图、字符串与函数lula8883 小时前
PVC-U、PVC-C、PVC-O 差一个字母,差的是三种增强路线数字工作台4 小时前
给 LangGraph 加一道可审计记忆:替换默认 Checkpointer,实现防篡改 + 崩溃不丢数据DKPT5 小时前
Python 的 Web 框架:选型选错的人,都踩了同一个坑2401_868534785 小时前
逻辑网络设计2601_967979125 小时前
python如何组织文件?python文件操作全介绍!青少儿编程课堂6 小时前
蓝桥杯·全国青少年信息素养大赛·电子学会Python/C++考级:扫描线与线段树求矩形面积并解析