0

I have a structure sw_list formatted as given below

 {'ports': [{'hw_addr': 'ee:b1:ab:b1:0e:a0', 'name': 's1-eth1', 'port_no': '00000001', 'dpid': '0000000000000201'}, 
            {'hw_addr': 'f6:83:4d:e4:41:7d', 'name': 's1-eth2', 'port_no': '00000002', 'dpid': '0000000000000201'}
                       ], 'dpid': '0000000000000201'}


for index,switch in enumerate(sw_list):
              dpid_str = dpid_to_str(switch.dp.id)

The above loop will print dpid_str which is '0000000000000201' ath the end of the structure. Now I want to access the contents of ports structure such as

Port 0: hw_addr,name,port_no etc

How do I do that?

2
  • I do not get the question. Can you try to rephrase? Commented Jun 5, 2014 at 23:15
  • 1
    So sw_list is not actually a list but rather a dict? Also, what is the dangling ) at the end supposed to close? Commented Jun 5, 2014 at 23:24

1 Answer 1

1
d={'ports': [{'hw_addr': 'ee:b1:ab:b1:0e:a0', 'name': 's1-eth1', 'port_no': '00000001', 'dpid': '0000000000000201'},
            {'hw_addr': 'f6:83:4d:e4:41:7d', 'name': 's1-eth2', 'port_no': '00000002', 'dpid': '0000000000000201'}
                       ], 'dpid': '0000000000000201'}

for i in d["ports"][0]:
    print "{} : {}".format(i,d["ports"][0][i])
hw_addr : ee:b1:ab:b1:0e:a0
name : s1-eth1
port_no: 00000001
dpid : 0000000000000201
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.