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()
相关推荐
xyq20248 小时前
ionic 单选框详解
开发语言
wWYy.8 小时前
STL:map与unordered_map
开发语言·c++·stl
m0_730115118 小时前
用户认证与授权:使用JWT保护你的API
jvm·数据库·python
kaisun648 小时前
树莓派4B上使用INMP441麦克风进行语音识别:从I2S配置到Python环境搭建全记录
python·语音识别·树莓派
亓才孓8 小时前
[Java笔试]易错点总结
java·开发语言
crescent_悦8 小时前
C++:Invert a Binary Tree
开发语言·c++
:1218 小时前
java---过滤器,监听器
java·开发语言
七夜zippoe8 小时前
Python 3.12+ 新特性深度解析:类型系统与性能革命
android·网络·python·类型系统·性能革命·3.12+
2401_873204658 小时前
C++与Docker集成开发
开发语言·c++·算法
实心儿儿8 小时前
C++ —— map和set的使用
开发语言·c++