Форум сайта python.su
0
Добрый день!
Есть такой код:
access = {'FastEthernet0/12': 10,
'FastEthernet0/14': 11,
'FastEthernet0/16': 17,
'FastEthernet0/17': 150}
access_template = ['switchport mode access',
'switchport access vlan',
'switchport nonegotiate',
'spanning-tree portfast',
'spanning-tree bpduguard enable']
a = []
access_conf = {}
for port in access:
a.clear()
for conf in access_template:
if conf == 'switchport access vlan':
a.append(str(conf) + ' ' + str(access[port]))
else:
a.append(conf)
# access_conf.append(a)
access_conf[port] = (a)
print(access_conf)access_conf = {'FastEthernet0/12': ['switchport mode access', 'switchport access vlan 10', 'switchport nonegotiate', 'spanning-tree portfast', 'spanning-tree bpduguard enable'], 'FastEthernet0/14': ['switchport mode access', 'switchport access vlan 11', 'switchport nonegotiate', 'spanning-tree portfast', 'spanning-tree bpduguard enable'], 'FastEthernet0/16': ['switchport mode access', 'switchport access vlan 17', 'switchport nonegotiate', 'spanning-tree portfast', 'spanning-tree bpduguard enable'], 'FastEthernet0/17': ['switchport mode access', 'switchport access vlan 150', 'switchport nonegotiate', 'spanning-tree portfast', 'spanning-tree bpduguard enable']}{'FastEthernet0/12': ['switchport mode access', 'switchport access vlan 150', 'switchport nonegotiate', 'spanning-tree portfast', 'spanning-tree bpduguard enable'], 'FastEthernet0/14': ['switchport mode access', 'switchport access vlan 150', 'switchport nonegotiate', 'spanning-tree portfast', 'spanning-tree bpduguard enable'], 'FastEthernet0/16': ['switchport mode access', 'switchport access vlan 150', 'switchport nonegotiate', 'spanning-tree portfast', 'spanning-tree bpduguard enable'], 'FastEthernet0/17': ['switchport mode access', 'switchport access vlan 150', 'switchport nonegotiate', 'spanning-tree portfast', 'spanning-tree bpduguard enable']}Отредактировано Tramp (Май 31, 2017 20:58:44)
Офлайн
76
Дональд,
вот возможное решение
access = {'FastEthernet0/12': 10, 'FastEthernet0/14': 11, 'FastEthernet0/16': 17, 'FastEthernet0/17': 150} access_template = ['switchport mode access', 'switchport access vlan', 'switchport nonegotiate', 'spanning-tree portfast', 'spanning-tree bpduguard enable'] for port, value in access.items(): access[port] = access_template.copy() access[port][1] += ' ' + str(value) print(access)
Офлайн
0
Спасибо! Как все просто оказалось!
Не подскажите, почему мой вариант не работает?
Офлайн