Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 DevNet Help
#1
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.
Quote

Top Page

Messages In This Thread
DevNet Help - by benniehanas - Aug-07-2019, 03:29 PM
RE: DevNet Help - by ichabod801 - Aug-07-2019, 05:25 PM
RE: DevNet Help - by benniehanas - Aug-07-2019, 07:41 PM
RE: DevNet Help - by ichabod801 - Aug-08-2019, 01:37 AM
RE: DevNet Help - by benniehanas - Aug-08-2019, 06:05 PM
RE: DevNet Help - by ichabod801 - Aug-08-2019, 06:28 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)