我尝试使用使用regex的textfsm
模块,并将数据导入到文本文件中。以下是我的代码:
from netmiko import ConnectHandler
from textfsm import *
cisco_device = { 'device_type' : 'cisco_ios', 'ip' : 'x.x.x.x', 'username':'****0', 'password':'***9'}
net_connect = ConnectHandler(**cisco_device)
fo=("test.txt" , 'w')
output = net_connect.send_command("show ip int brief")
re_table = TextFSM('xr_show_int_br','r')
data = re_table.ParseText(output)
print (output)
print(re_table.header)
for test in (re_table.header):
fo.write(test)
fo.write("\n")
for row in data:
for temp_row in data:
fo.write(temp_row)
fo.write("\n")
fo.close
但我得到了一个错误:
回溯(最近一次呼叫): 文件“/Users/gtmy200/Desktop/Py/测试.py“,第11行,英寸 re_table=TextFSM('xr_show_int_br','r') 文件“/库/框架/Python.framework/Versions/3.4/lib/python3.4/site-packages/文本fsm.py“,第549行,ininit 模板.seek(0) AttributeError:“str”对象没有属性“seek”
似乎xr_show_int_br需要是一个文件对象。 您得到错误here
相关问题 更多 >
编程相关推荐