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()
相关推荐
知识分享小能手12 分钟前
Flask入门学习教程,从入门到精通,Flask智能租房——前期准备 知识点详解(5)
python·学习·flask
Curvatureflight16 分钟前
【架构实战】生产级大模型 API 接入指南:流式响应(Streaming)异常处理与监控闭环
python·架构
smj2302_796826521 小时前
解决leetcode第3943题递增后的数对数量
数据结构·python·算法·leetcode
এ慕ོ冬℘゜1 小时前
JS 前端基础面试题
开发语言·前端·javascript
浩少7021 小时前
【无标题】
java·开发语言
deepin_sir1 小时前
06 Chroma_持久化与生产环境部署实战
python
nnsix2 小时前
C# 字符串 根据换行符分割
开发语言·c#
Vallelonga2 小时前
Rust Conversion 工具 trait AsRef AsMut
开发语言·rust
Vallelonga2 小时前
Rust 中的“解引用”和智能指针与 MutexGuard 等
开发语言·rust
小鱼仙官2 小时前
Windonws 视频存储,10s/不限时
开发语言·qt·音视频