Answer the question
In order to leave comments, you need to log in
[[+content_image]]
Why does Python swear in a loop?
All the best!
Help me figure it out... there is an answ
variable that is equal to:
[[u'!re', {u'=invalid': u'false', u'=disabled': u'false', u'=.id': u'*2', u'=interface': u'br12-staff', u'=dynamic': u'false', u'=actual-interface': u'br12-staff', u'=comment': u'in', u'=network': u'10.10.12.0', u'=address': u'10.10.12.217/24'}], [u'!re', {u'=invalid': u'true', u'=disabled': u'true', u'=.id': u'*3', u'=interface': u'ether1-gateway', u'=dynamic': u'false', u'=actual-interface': u'ether1-gateway', u'=comment': u'RouterOS Upgrade', u'=network': u'172.16.0.0', u'=address': u'172.16.0.2/24'}], [u'!done', {}]]
print answ[0][1][u'=address']
for x in answ:
print x[1]['=address']
for x in answ:
print x[1][u'=address']
print x[1][u'=address'] KeyError: u'=address'
Answer the question
In order to leave comments, you need to log in
https://docs.python.org/3/library/stdtypes.html#di... you have [u'!done', {}]
in your list of lists , the second element is an empty dictionary, respectively, in it no '=address' key
You need to figure out what you have in the x variable at each iteration of the loop.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question