def getValue(d, key):
for k, v in d.iteritems():
print "{0} == {1}".format(k, key)
if k == key:
return v
elif isinstance(v, dict):
getValue(v, key)
logging.error("Cannot find key in dictionary")
return ""
#d = getting the dictionary
getValue(d, "error_frames")
From the print statement I inserted in the function, I clearly see “error_frames == error_frames” appear in the console, but the if statement is not getting executed. Why? The dictionary is constructed by parsing xml with the module xmltodict.
Perhaps the print statement is being executed from a nested recursive call.
Should that be
return getValue(key)?