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
相关推荐
“AI国潮设计-小江”6 小时前
《Python+SDXL实战:用ControlNet精准控制“英歌舞翻糖吐司”构图,附批量生成脚本》程序喵大人6 小时前
【C++入门】编译链接模型 - 01 一个 C++ 程序是怎样变成可执行文件的wenwen_chao6 小时前
Python学习与开发资源合集:实用技巧与工具推荐for_ever_love__7 小时前
函数——参数、lambda、*args与作用域东莞市云毅网络有限公司7 小时前
企业资料时效性判定:Last-Modified、正文日期与版本字段三路交叉Query*7 小时前
深入浅出LangGraph【一】_基础篇sunshine22 girl8 小时前
Java学习七 Java 项目实战1-项目创建和主页面搭建XiaoMaqqqq8 小时前
市面上正规的IP驱动产业新场景新工具哪家强菜鸟~noob2338 小时前
【电子战】第三季预告—波武器与电子系统强力毁伤ShyanZh8 小时前
【Python3基础】19-Socket 与 TCP、UDP 编程