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
相关推荐
Liquad Li1 小时前
Salesforce 主流认证方式、流程、适用场景LOVE️YOU4 小时前
Python 中 Tuple 为什么有时可 Hash,有时不可 Hash?李永奉4 小时前
C语言-指针函数与函数指针及回调函数的使用小oo呆4 小时前
【学习心得】迭代器和可迭代对象AC赳赳老秦5 小时前
采集行为合规自检:OpenClaw 自动校验 robots 协议与采集频率,规避违规采集风险钱栈up5 小时前
mvn compile 卡死在 javac 阶段:一次类型不匹配的排查与修复迅猛龙办公室5 小时前
Python输出当前计算机的系统日期和时间杨丰玮4185 小时前
C语言基础知识(一)————各类符号的含义与输入输出库(stdio)程序猿编码6 小时前
工业视觉多任务方案:可编程梯度信息视觉框架,训练评估 + C++ 部署完整实战XiaoMaqqqq6 小时前
知名的IP驱动产业新场景新工具