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
相关推荐
Solyn_HAN几秒前
Python 生信进阶:Biopython 库完全指南(序列处理 + 数据库交互)九河_11 分钟前
解决pip install gym==0.19.0安装失败问题红豆诗人11 分钟前
C语言进阶知识--文件操作麦麦鸡腿堡1 小时前
Java绘图技术热爱编程的OP1 小时前
Linux进程池与管道通信详解:从原理到实现iamohenry2 小时前
古早味的心理咨询聊天机器人Blossom.1186 小时前
移动端部署噩梦终结者:动态稀疏视觉Transformer的量化实战AiXed6 小时前
PC微信协议之AES-192-GCM算法灵光通码7 小时前
神经网络基本概念武子康8 小时前
Java-171 Neo4j 备份与恢复 + 预热与执行计划实战