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 来构建的。
最佳答案
.format
调用对象的__str__
方法,不同对象的输出可以相同。
In [1]: a = 1
In [2]: b = '1'
In [3]: print '{0} == {1}'.format(a, b)
1 == 1
In [4]: a == b
Out[4]: False
关于python - 为什么这些字符串不相等? (Python),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10800942/