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 小时前
提取矩阵某一行或某一列元素
开发语言·人工智能·线性代数·算法·matlab·矩阵
小江的记录本4 小时前
【JVM虚拟机】垃圾回收GC:四种引用类型:强引用、软引用、弱引用、虚引用(附《思维导图》+《面试高频考点清单》)
java·jvm·spring boot·后端·python·spring·面试
APIshop5 小时前
Python 获取 1688 商品采集 API 接口 | 工厂货源自动化对接商品信息 | 无需选品
运维·python·自动化
deepin_sir5 小时前
10 - 函数
开发语言·python
z落落5 小时前
C#String字符串
开发语言·c#·php
猫头虎-前端技术5 小时前
JS 作用域与闭包:从变量提升到闭包陷阱的超详细解析
开发语言·javascript·云计算·bootstrap·ecmascript·openstack·perl
charlee446 小时前
《GIS基础原理与技术实践》配套案例(Python版)
python·conda·numpy·gis·环境配置
枫叶林FYL6 小时前
项目十:事件溯源仓储管理系统(WMS)仿真实现
开发语言·python
繁华落尽,倾城殇?6 小时前
[C++11] : atomic,nullptr,default/delete,enum class
开发语言·c++·c++11·nullptr·atomic·enum class·default/delete
01_ice6 小时前
C语言数据在内存中的存储
c语言·开发语言