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()
相关推荐
xlq223224 小时前
10.string(上)
开发语言·c++
合作小小程序员小小店4 小时前
舆情,情感微博系统demo,基于python+qt+nlp,开发语言python,界面库qt,无数据库版,数据来自第三方网站获取,
开发语言·pytorch·qt·自然语言处理·nlp
烟锁池塘柳04 小时前
【已解决】解决CondaVerificationError:PyTorch安装包损坏问题
人工智能·pytorch·python
hashiqimiya4 小时前
c++的头文件使用
开发语言·c++·算法
panamera124 小时前
C++中vector
开发语言·c++
拳里剑气4 小时前
C++:string的使用
开发语言·c++·学习方法
程序员爱钓鱼4 小时前
Python编程实战 | 函数与模块化编程 - 第三方库的安装与管理(pip使用)
后端·python·ipython
国服第二切图仔4 小时前
Rust开发之Result枚举与?运算符简化错误传播
开发语言·python·rust
程序员爱钓鱼4 小时前
Python编程实战 | 面向对象与进阶语法-类与对象的概念
后端·python·ipython
Dovis(誓平步青云)5 小时前
《静态库与动态库:从编译原理到实战调用,一篇文章讲透》
linux·运维·开发语言