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()
相关推荐
tkevinjd12 分钟前
MiniCode 项目详解6:原项目控制系统的10个缺陷(已修复)
python·llm·agent
星栈独行1 小时前
翻完 Pi 源码:它和 Codex、Claude Code 有何不同
开发语言·javascript·人工智能·程序人生
dNGUZ7UGj1 小时前
10分钟完成第一个Python小游戏
python·django
没有梦想的咸鱼185-1037-16632 小时前
AI-Python机器学习与深度学习技术:CNN/Transformer/扩散模型、SHAP可解释及Hermes智能体自动化
人工智能·python·深度学习·机器学习·chatgpt·cnn·transformer
qq_448011162 小时前
C语言中的变量和函数的定义与声明
android·c语言·开发语言
霸道流氓气质2 小时前
SpringBoot中通用工具类库(Utils)封装与使用实践
spring boot·后端·python
孫治AllenSun3 小时前
【DataX】生产环境搭建DataX集群案例
java·开发语言·jvm
Draina4 小时前
CBC填充预言攻击-CBC Padding Oracle Crypto Attack
python·安全·web安全·网络安全·密码学·安全性测试
c238564 小时前
把 C++ 内存分配拆透:new 与 malloc 的三层血缘
开发语言·c++·算法
Angel Q.4 小时前
特征提取 | DINO 到 DINOv3
图像处理·python