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()
相关推荐
CUMT_DJ20 小时前
matlab计算算法的运行时间
开发语言·算法·matlab
weixin_5142218521 小时前
FDTD与matlab、python耦合
python·学习·matlab·fdtd
Overboom1 天前
[C++] --- 常用设计模式
开发语言·c++·设计模式
Univin1 天前
C++(10.4)
开发语言·数据结构·c++
KyollBM1 天前
每日羊题 (质数筛 + 数学 | 构造 + 位运算)
开发语言·c++·算法
Paul_09201 天前
golang面经——map模块和sync.Map模块
开发语言
F_D_Z1 天前
数据集相关类代码回顾理解 | StratifiedShuffleSplit\transforms.ToTensor\Counter
python·torchvision·transforms
Univin1 天前
C++(10.5)
开发语言·c++·算法
haogexiaole1 天前
Java高并发常见架构、处理方式、api调优
java·开发语言·架构
张人玉1 天前
C# 通讯关键类的API
开发语言·c#