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()
python往excel中写端口信息
Guaiacum_2024-10-12 23:13
相关推荐
weelinking7 小时前
【产品】12_接入数据库——让数据永久保存石山代码7 小时前
ArrayList / HashMap / ConcurrentHashMap程序大视界7 小时前
【Python系列课程】Python正则表达式(下):环视、命名分组与日志实战TickDB7 小时前
美股行情 API 接入避坑:REST 快照、WebSocket 推送、盘前盘后数据的边界枫叶v.8 小时前
Agent 分层存储架构设计:从记忆方法到中间件选型水兵没月8 小时前
逆向实战小记——某ToB商城网站分析学习程序员小远8 小时前
Python自动化测试框架及工具详解sleven fung9 小时前
MinerU与BabelDOC与KTransformers与OpenAI API库小毛驴8509 小时前
spring-boot-maven-plugin,maven-compiler-plugin 功能对比萤萤七悬9 小时前
【Python笔记】AI帮实现CLI工具-使用argparse.ArgumentParser接收命令参数