python往excel中写端口信息

复制代码
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()
相关推荐
嵌入式-老费2 分钟前
esp32开发与应用(看门狗测试)
java·开发语言·数据库
闫有尽意无琼6 分钟前
qt控件未指定父对象或delete致堆内存泄露
开发语言·qt
老徐聊GEO7 分钟前
2026年:巧妙引导,让AI回答中自然融入你的品牌
大数据·人工智能·python
winfredzhang7 分钟前
给本地图库的“人“加上属性:DeepFace + MediaPipe Pose 联合分析(含 GitHub 镜像踩坑)
python·sqlite·mediapipe·打标签·场景和属性
Cx330❀8 分钟前
【Linux网络】从零定制应用层协议:黏包问题、全双工缓冲区与 Jsoncpp 序列化深度解析
linux·运维·服务器·开发语言·网络·c++·人工智能
cuso4win11 分钟前
Agent 项目里的 Eval 到底是什么?怎么分类?不同项目应该怎么评测?
笔记·python·agent·eval
山东布谷网络科技11 分钟前
海外直播语聊APP功能与UI升级的关键关注点
开发语言·ui·app store·谷歌上架·海外直播app开发·海外语聊平台搭建·多语言直播平台定制
Metaphor69212 分钟前
使用 Python 将 PDF 转换为 PDF/A
python·pdf
程序猿零零漆13 分钟前
Python进阶之路:正则表达式、高级语法与核心数据结构(链表、二叉树)全解析
数据结构·python·正则表达式
江屿风13 分钟前
C++图论基础Bellman-Ford与spfa算法如何判断负环
开发语言·c++·笔记·算法·图论