AttributeError:“str”对象没有使用textfsm模块(regex)的属性“seek”

2024-09-27 17:37:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试使用使用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”


Tags: intestreforoutputdatadeviceshow

热门问题