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")
从我在函数中插入的打印语句中,我清楚地看到控制台中出现“error_frames == error_frames”,但 if 语句没有被执行。为什么?字典是通过使用模块 xmltodict 解析 xml 来构造的。