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()
相关推荐
橡晟3 小时前
深度学习入门:让神经网络变得“深不可测“⚡(二)
人工智能·python·深度学习·机器学习·计算机视觉
墨尘游子3 小时前
神经网络的层与块
人工智能·python·深度学习·机器学习
倔强青铜33 小时前
苦练Python第18天:Python异常处理锦囊
开发语言·python
u_topian4 小时前
【个人笔记】Qt使用的一些易错问题
开发语言·笔记·qt
企鹅与蟒蛇4 小时前
Ubuntu-25.04 Wayland桌面环境安装Anaconda3之后无法启动anaconda-navigator问题解决
linux·运维·python·ubuntu·anaconda
autobaba4 小时前
编写bat文件自动打开chrome浏览器,并通过selenium抓取浏览器操作chrome
chrome·python·selenium·rpa
珊瑚里的鱼4 小时前
LeetCode 692题解 | 前K个高频单词
开发语言·c++·算法·leetcode·职场和发展·学习方法
AI+程序员在路上4 小时前
QTextCodec的功能及其在Qt5及Qt6中的演变
开发语言·c++·qt
xingshanchang4 小时前
Matlab的命令行窗口内容的记录-利用diary记录日志/保存命令窗口输出
开发语言·matlab
Risehuxyc4 小时前
C++卸载了会影响电脑正常使用吗?解析C++运行库的作用与卸载后果
开发语言·c++