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()
相关推荐
Solyn_HAN几秒前
Python 生信进阶:Biopython 库完全指南(序列处理 + 数据库交互)
python·生物信息学·biopython
九河_11 分钟前
解决pip install gym==0.19.0安装失败问题
开发语言·python·pip·gym
红豆诗人11 分钟前
C语言进阶知识--文件操作
c语言·开发语言·文件操作
麦麦鸡腿堡1 小时前
Java绘图技术
java·开发语言
热爱编程的OP1 小时前
Linux进程池与管道通信详解:从原理到实现
linux·开发语言·c++
iamohenry2 小时前
古早味的心理咨询聊天机器人
python·自然语言处理
Blossom.1186 小时前
移动端部署噩梦终结者:动态稀疏视觉Transformer的量化实战
java·人工智能·python·深度学习·算法·机器学习·transformer
AiXed6 小时前
PC微信协议之AES-192-GCM算法
前端·数据库·python
灵光通码7 小时前
神经网络基本概念
python·神经网络
武子康8 小时前
Java-171 Neo4j 备份与恢复 + 预热与执行计划实战
java·开发语言·数据库·性能优化·系统架构·nosql·neo4j