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()
相关推荐
love_summer1 分钟前
深入理解Python流程控制:从算法设计到顺序执行机制(附代码)
python
山沐与山3 分钟前
【Python】深入理解Python Web框架:从Flask到FastAPI的并发之路
python·flask·fastapi
嫂子的姐夫4 分钟前
011-AES:深证信
爬虫·python·逆向
海奥华24 分钟前
Golang Channel 原理深度解析
服务器·开发语言·网络·数据结构·算法·golang
代码游侠6 分钟前
学习笔记——MQTT协议
开发语言·笔记·php
love530love6 分钟前
Flash Attention 2.8.3 在 Windows + RTX 3090 上成功编译与运行复盘笔记(2026年1月版)
人工智能·windows·笔记·python·flash_attn·flash attention·z-image
渡我白衣12 分钟前
计算机组成原理(13):多路选择器与三态门
开发语言·javascript·ecmascript·数字电路·计算机组成原理·三态门·多路选择器
@zulnger12 分钟前
python 学习笔记(异常对象)
笔记·python·学习
HUST13 分钟前
C语言 第十讲:操作符详解
c语言·开发语言
No0d1es17 分钟前
2025年12月 GESP CCF编程能力等级认证Python七级真题
python·青少年编程·gesp·ccf