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
相关推荐
曲径海盗19 分钟前
【Python 学习第 65 天】字典基础Wellijohn28 分钟前
Docker 瘦身、手写 MCP、异步并发:被问得最多的 12 个问题,一次答完VW_4044 小时前
csdn-2026-11-23-第一站踩坑yiangL_4 小时前
课后作业4:基于 Python 的古诗词词云可视化(P205)Dmz丶4 小时前
前端转 AI 100 天 Day 52:RAG 项目实战(一)——从零搭建企业知识库geovindu6 小时前
rust: Functional Options Patternskywalk81637 小时前
把「假成功」赶出工具层:lightharness 两天升级复盘(4×5 模式矩阵 + 工具层 5 个缺陷)敲上瘾7 小时前
Qt控件通用属性:geometry、qrc资源到QSS样式表等卷无止境8 小时前
用 SimPy 做离散事件仿真:时钟不走步,事件自己排队听情歌落俗8 小时前
嵌入式学习1-C语言基础语法与STM32实践