我如何遍历并从以下列表中提取值,我在下面使用的代码仅获取键值。
> [{'filename': <docxtpl.InlineImage object at 0x040038D0>, 'desc':
> u'dfgdgfdfg'}, {'filename': <docxtpl.InlineImage object at
> 0x04014930>, 'desc': u'dfgdfgdfg'}, {'filename': <docxtpl.InlineImage
> object at 0x04014A90>, 'desc': u'fghfghfh'}]
代码:
for k,v in audit_items_list:
print audit_items_list
print k
print v
如果我使用 k.value()
。我收到以下错误:
AttributeError: 'str' object has no attribute 'values'
更新: 感谢所有帮助,但我实际上想在每次迭代中获取文件名和描述符的值…
原文由 Ossama 发布,翻译遵循 CC BY-SA 4.0 许可协议
外层是列表,内层是字典。你只需要更深入一层。