最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python 3.x - Return Tuple through loop - Stack Overflow

programmeradmin2浏览0评论

I'm trying to gather interface details for a Palo Alto network device; however, when I return a tuple, it is returning the last element of the for loops.

#find interface using palo sdk
def check_interface(hostname):            
    show_interface_all = connect_to_fw(hostname).op('show interface "all"', xml=True) # func called from some other func
    interface_jason = xmltodict.parse(show_interface_all)

    for int_details in interface_jason["response"]["result"]["hw"]["entry"]:
        for i in interface_jason["response"]["result"]["ifnet"]["entry"]:
            zone = i["zone"]
            ip =i["ip"]
            break
        int =int_details["name"]   
        state = int_details["state"] 
        result_1 = (int,state,ip,zone) # tuple
    return result_1

Expected output of this would be:

('ethernet1/3', 'down', '192.168.2.1/30', DMZ)
('ethernet1/4', 'down', '192.168.2.1/30', trust)
('ethernet1/7', 'up', '192.168.2.1/30', untrust)

Hhowever I'm getting only a single value which is the last value of the loop:

  ('ethernet1/3', 'down', '192.168.2.1/30', DMZ)

How do I fix it?

发布评论

评论列表(0)

  1. 暂无评论