首页 > 解决方案 > 'dict' 对象没有属性 'value' 但是当我打印出来时我在字典中看到它

问题描述

当我运行这行代码时:print(response.keys());

我得到这个回应: dict_keys(['@odata.context', 'value'])

当我运行这行代码时:print(response.value);

我得到这个回应:AttributeError: 'dict' object has no attribute 'value'

当我打印出整个字典时,我看到了属性值。下面是打印出来的部分。我可以清楚地将价值视为一种属性。

{'@odata.context': '$metadata#Property(ListPrice,YearBuilt,ListingKey)', 'value': [{'ListPrice': 895000.0, 'YearBuilt': 0, 'ListingKey': '1000006'}, {'ListPrice': 84800.0, 'YearBuilt': 0, 'ListingKey': '1000096'}

任何想法发生了什么?

标签: pythondictionarydata-science

解决方案


字典的成员函数被调用.values()而不是.value。你错过了s和括号。

尝试:

 print(resonse.values())

或者尝试访问元素:

 print(response['value'])

哪里value恰好是字典键。显然,这可能会令人困惑。


推荐阅读