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
相关推荐
小刘在重生~25 分钟前
Java 常用类|包装类 装箱拆箱、Integer 缓存面试题2601_9620994644 分钟前
Python xlwt设置excel单元格字体及格式菜鸟~noob2331 小时前
【电子战】 第01篇:噪声、门限与虚警/检测概率(PFA/PD)【含matlab代码】奇牙coding1231 小时前
GPT-6-Astra API 接入教程:OpenRouter 路由配置 + Python/curl 示例 + 静默降级踩坑2601_962298272 小时前
Python与Selenium结合的Web自动化测试全流程实践教程lzx_0022 小时前
C++11(一)天衍四九-2 小时前
第一章:从 LLM 到 Agent —— DeepSeek Harness 入门529宝宝起名网2 小时前
用 Python 实现名字寓意评分算法:基于 NLP 语义分析的名字内涵深度评估2601_962298672 小时前
Python:对象缓存优化机制(CPython)未来之窗软件服务2 小时前
计算机二级[英文]-C 字符串移动—东方仙盟