pythonlist:选择相应索引的两个列表

2024-06-16 10:30:40 发布

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

list1 = ['ibsdr1', 'ibsds1', 'ibsds1', 'ibsdm2', 'ibsdm2', 'ibsdm2']

list2 = ['Gig 0/0/1', 'Gig 6/47', 'Gig 5/47', 'Gig 6/7', 'Gig 6/3', 'Gig 5/3']

我有两个列表,我需要在list1的每个设备上运行下面的脚本,每个设备的端口都是list2。你知道吗

list1[0]。只应选择list2[0],不应选择list2的其余部分。你知道吗

每个列表索引应该只选择它们各自的索引。你知道吗

ibsdr1 should select Gig 0/0/1
ibsds1 should select Gig 6/47
ibsds1 should select Gig 5/47
ibsdm2 should select Gig 6/7
ibsdm2 should select Gig 6/3
ibsdm2 should select Gig 5/3

下面是我试图运行的脚本,但我没有得到正确的输出。list1索引正在逐个选择所有list2索引。你知道吗

for (sw, op) in zip(list1, list2):
    connect = {'device_type': 'cisco_ios', 'ip': sw, 'username': user, 'password': password, 'port': 22}
    net_connect1 = ConnectHandler(**connect)
    opout = net_connect1.send_command_expect('show interfaces '+op+' switchport')
    opp.append(opout)
    print (opp)

Tags: 脚本列表netconnectpasswordswselectop