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()
相关推荐
小北方城市网4 分钟前
第 8 课:Python 面向对象进阶 —— 类方法、静态方法与高级特性
网络·python·microsoft·数据库架构
belldeep25 分钟前
python:markdown + python-docx 将 Markdown 文件格式转为 Word 文档
python·word·markdown·docx
CDwenhuohuo38 分钟前
uniapp去掉手机状态栏 全屏展示
开发语言·javascript·uni-app
小钻风336643 分钟前
软件测试: 从入门到实践(接口自动化)
软件测试·python·自动化
别多香了1 小时前
Python 基础--循环判断&字符串
开发语言·python
老歌老听老掉牙1 小时前
使用 Matplotlib 自定义坐标轴字体及刻度样式详解
python·matplotlib
早点睡觉好了1 小时前
JAVA中基本类型和包装类型的区别
java·开发语言
码农水水1 小时前
国家电网Java面试被问:二叉树的前序、中序、后序遍历
java·开发语言·面试
Respect@1 小时前
qml之TableViewColumn
开发语言·qml
股朋公式网2 小时前
斩仙飞刀、 通达信飞刀 源码
python·算法