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探索者20 小时前
LangGraph StateGraph 实战:状态机聊天机器人构建指南AI探索者20 小时前
LangGraph 入门:构建带记忆功能的天气查询 AgentFishCoderh21 小时前
Python自动化办公实战:批量重命名文件,告别手动操作躺平大鹅21 小时前
Python函数入门详解(定义+调用+参数)曲幽1 天前
我用FastAPI接ollama大模型,差点被asyncio整崩溃(附对话窗口实战)两万五千个小时1 天前
落地实现 Anthropic Multi-Agent Research System哈里谢顿1 天前
Python 高并发服务限流终极方案:从原理到生产落地(2026 实战指南)用户8356290780512 天前
无需 Office:Python 批量转换 PPT 为图片markfeng82 天前
Python+Django+H5+MySQL项目搭建GinoWi2 天前
Chapter 2 - Python中的变量和简单的数据类型