Aug-07-2019, 03:29 PM
I am begenning DevNet from a pure Networking background. I have some code I'm looking at from 'Network Programmability and Automation' book. Don't know how '
temp['name'] = name' works.
vlans_list = [ 'vlan 10', 'name DATA', 'vlan 20', 'name VOICE', 'vlan 30', 'name WIRELESS' ] vlans = [] for item in vlans_list: if 'vlan' in item: temp = {} id = item.strip().strip('vlan').strip() temp['id'] = id elif 'name' in item: name = item.strip().strip('name').strip() temp['name'] = name vlans.append(temp)I see strip stripping off vlan and whitespace with the string of strips. Then the string is left with only '10' as in the first string in vlans_list. I don't know where id comes from. Does
var['string'] = 'string'write the value declared for that line in the iteration? I cannot find this usage in documentation. Basically this script is replacing/stripping 'vlan' for 'id', but code confuses me no matter how simple it seems.