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
相关推荐
闲猫5 分钟前
LangGraph / Capabilities / StoresQH139292318808 分钟前
NVIDIA H200 H300服务器pjj1985416 分钟前
机器学习-NumPy2OPEN-F29 分钟前
Python进阶教程:单元测试与代码质量阿里嘎多学长29 分钟前
2026-08-20 GitHub 热点项目精选其实防守也摸鱼38 分钟前
Codex破局:前端组件秒级生成的技术文章大纲Logintern091 小时前
装饰器和洋葱模式的区分冻柠檬飞冰走茶1 小时前
《数据结构实验指导-C++语言版》 在顺序表 list 中查找元素 xBrilliantwxx1 小时前
【C++】 高阶数据结构图(1)并查集lancyu1 小时前
# Agent Loop:AI Agent 的唯一直心骨