2017-06-23 5 views
0
from netmiko import ConnectHandler  
from textfsm import * 

cisco_device = { 'device_type' : 'cisco_ios', 'ip' : 'x.x.x.x', 'username':'gtomy200', 'password':'xxxxx'} 
net_connect = ConnectHandler(**cisco_device) 

fo=("testme.txt" , 'w') 

output = net_connect.send_command("show int brief") 

re_table = TextFSM(open('xr_show_int_br','r'))  

data = re_table.ParseText(output) 

print (output) 

for s in re_table.header: 

      fo.write("%s;" %s) 

fo.write("\n") 

for row in data: 
     print (row) 
     for s in row: 

       fo.write("%s" %s) 
       fo.write("\n") 

fo.close() 

を書きながら「タプル」オブジェクトが属性「書き込み」エラーを持っていない、誰かが助けることができる、以下のエラーに関する:はAttributeError:ファイルに

 
Traceback (most recent call last): 
    File "/Users/gtomy200/Desktop/Py/test.py", line 20, in 
    fo.write("%s;" %s) 
AttributeError: 'tuple' object has no attribute 'write' 

答えて

0

あなたはあなたにopenファイルを確実にしたいです:

fo = open("testme.txt" , 'w') 
# ^^^^ 

それはあなたが2組に書き込みをしようとしていたある通り:

fo = ("testme.txt", 'w') 
# ^no open 

これは動作しません。

0

foは、タプルです。ファイル操作にはwith open()を使用してください。より安全で簡単です。

with open ("myfile.txt","w") as ff: 
    ff.write("string") #you can't use anything but strings in here, 
         #so convert your variables to string 
関連する問題