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
相关推荐
等我调个Bug9 分钟前
C++智能指针通俗讲解黑化旺仔26 分钟前
【OC】Runtime:类元数据、加载初始化与消息派发Felven34 分钟前
C. Removing Smallest Multiples云和数据.ChenGuang1 小时前
光哥说Python 循环导入(Circular Import)深度解析:成因、排查与解决方案星夜离尘561 小时前
MATLAB 工程实验:滞回加持续时间报警,把 UNKNOWN 留在状态机里TomEval1 小时前
【测AI】第16篇:模型公平性与可解释性测试 — AI 的偏见与黑箱fengci.1 小时前
BUUCTF(困难部分)田里的水稻1 小时前
FA_CNN卷积神经网络四---线性层及其拉平PyTorchHighcharts.js1 小时前
BI可视化图表“维护难”问题的解决方案钱栈up1 小时前
GitHub热榜上手|Claude插件:4.3万星官方目录