我正在尝试使用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/gtomy200/Desktop/Py/test.py”,第 11 行,在 re_table = TextFSM('xr_show_int_br','r') 文件“/Library/Frameworks/Python.framework /Versions/3.4/lib/python3.4/site-packages/textfsm.py",第 549 行,在init template.seek(0) AttributeError: 'str' 对象没有属性 'seek'