import pandas标签:__,testfsm,0.00%,0Te3,0.01%,up,down From: https://www.cnblogs.com/yc-tec/p/17129209.html
import textfsm
import pandas as pd
from textfsm import TextFSM
def tracer(str1):
info = TextFSM(open('testfsm.tmp')).ParseText(str1) # <class 'list'>
header = (TextFSM(open('testfsm.tmp')).header)
data = info
a = pandas.DataFrame(data,columns=header)
print(a)
str1 = '''
CQST-M-PUB-CORE-RUIJIE-N18010-01-ITC11#show inter br
down: link down
*down: administratively down
disabled: err-disabled(Please reference to command [show interfaces status err-disabled] for detail.)
Interface Link Stat Protocol Stat Input Usage Output Usage inErrors outErrors
------------ ------------ ------------- ---------------- ---------------- ------------ ------------
Te3/1 up up 0.01% 0.01% 0 0
Te3/2 up up 0.03% 0.02% 0 0
Te3/3 up up 0.02% 0.01% 0 0
Te3/4 up up 0.01% 0.01% 0 0
Te3/5 up up 0.01% 0.01% 0 0
Te3/6 up up 0.01% 0.00% 0 0
Te3/7 up up 0.01% 0.01% 0 0
Te3/8 up up 0.01% 0.01% 0 0
Te3/9 up up 0.01% 0.01% 0 0
Te3/10 up up 0.01% 0.01% 0 0
Te3/11 up up 0.01% 0.01% 0 0
Te3/12 up up 0.01% 0.01% 0 0
Te3/13 *down down 0.00% 0.00% 0 0
Te3/14 *down down 0.00% 0.00% 0 0
Te3/15 *down down 0.00% 0.00% 0 0
Te3/16 *down down 0.00% 0.00% 0 0
Te3/17 *down down 0.00% 0.00% 0 0
Te3/18 *down down 0.00% 0.00% 0 0
Te3/19 *down down 0.00% 0.00% 0 0
'''
if __name__ == "__main__":
key = tracer(str1)
print(key)