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
相关推荐
满怀冰雪几秒前
23-PaddleClas 数据集、配置文件与训练参数详解zh_xuan10 分钟前
c++ jthread旧梦952710 分钟前
Java 捕获多个异常:从基础语法到最佳实践笔触狂放1 小时前
第3章 抓取静态网页数据海兰1 小时前
【 Python 量化交易】开篇pt10431 小时前
网络自动化Python课程:Netconf与Restconf及Cisco自动化配置实验slacker-kian1 小时前
[笔记]-什么是相似性搜索?阿童木写作1 小时前
跨境电商图片翻译工具,批量翻译视频字幕还免费sukioe1 小时前
城智连响:基于 LangGraph 与四库分层架构的城市公共设施智能报修与派单系统我的xiaodoujiao1 小时前
Django 基础知识详细图文教程 4-Django 视图定义与使用