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
相关推荐
橡晟3 小时前
深度学习入门:让神经网络变得“深不可测“⚡(二)墨尘游子3 小时前
神经网络的层与块倔强青铜33 小时前
苦练Python第18天:Python异常处理锦囊u_topian4 小时前
【个人笔记】Qt使用的一些易错问题企鹅与蟒蛇4 小时前
Ubuntu-25.04 Wayland桌面环境安装Anaconda3之后无法启动anaconda-navigator问题解决autobaba4 小时前
编写bat文件自动打开chrome浏览器,并通过selenium抓取浏览器操作chrome珊瑚里的鱼4 小时前
LeetCode 692题解 | 前K个高频单词AI+程序员在路上4 小时前
QTextCodec的功能及其在Qt5及Qt6中的演变xingshanchang4 小时前
Matlab的命令行窗口内容的记录-利用diary记录日志/保存命令窗口输出Risehuxyc4 小时前
C++卸载了会影响电脑正常使用吗?解析C++运行库的作用与卸载后果