我正在尝试将 pyats 的输出打印到丰富的模块。这是输出
{
"cdp": {
"index": {
"1": {
"capability": "R S I",
"device_id": "SW22.lab.com",
"hold_time": 150,
"local_interface": "Ethernet0/0",
"platform": "",
"port_id": "LinuxUniEth0/0"
},
"2": {
"capability": "R S I",
"device_id": "SW23.lab.com",
"hold_time": 147,
"local_interface": "Ethernet0/0",
"platform": "",
"port_id": "LinuxUniEth0/0"
},
当我需要从功能打印到 local_interface 时。有了这条线
for k, v in preoutput['cdp'].items():
deid = v.get('device_id')
loint = v.get('local_interface')
holdt = v.get('hold_time')
portid = v.get('port_id')
table.add_row(k, deid)
我只打印出索引字。