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
相关推荐
深念Y17 小时前
Windows幽灵端口占用:HNS如何无声偷走你的端口宸津-代码粉碎机17 小时前
Jar热部署进阶实战|修复原生方案OOM与类冲突问题,生产级无BUG优化方案未知违规用户19 小时前
大模型项目:RAG项目实战与FlagEmbedding模型IT小盘1 天前
03-大模型API不只是发送Prompt-流式输出超时重试与异常处理Zzz不能停1 天前
个人博客系统系统---测试报告【笔耕云】互联网中的一颗神经元1 天前
小白python入门 - 39. 采集流水线小项目Wang's Blog1 天前
Go-Zero 项目开发22:用户群聊功能的实现与完善a1117761 天前
坦克大战3D Three.js 3D (开源项目)郭老二1 天前
【Python】常用模块:xmlrpc名字还没想好☜1 天前
Python itertools 实战:用 groupby、chain、islice 优雅处理大数据流