如果我不尝试迭代,为什么会得到“bool”类型是不可迭代的?

2024-05-16 12:15:01 发布

您现在位置:Python中文网/ 问答频道 /正文

如果我只是在做一些dict查找和比较,那么为什么会出现“bool is not iterable”错误,请具有高超python技能的人解释一下?

这是堆栈跟踪的最后一行:

---> 54     if 'identifiers' in document and 'doi' in document['identifiers'] and document['identifiers']['doi'] == row['doi']:
     55         print 'Found DOI'
     56         return True

TypeError: ("argument of type 'bool' is not iterable", u'occurred at index 2914')

如果密钥不存在,使用try/except来尝试读取我的dict并捕获,这是最佳实践吗?


Tags: andinifis堆栈技能错误doi