python - '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'}
任何想法发生了什么?
解决方案
字典的成员函数被调用.values()
而不是.value
。你错过了s
和括号。
尝试:
print(resonse.values())
或者尝试访问元素:
print(response['value'])
哪里value
恰好是字典键。显然,这可能会令人困惑。
推荐阅读
- c++ - 动态数组似乎比它的动态大小变量大
- go - 'protoc-gen-go-grpc: program not found or is not executable',尽管付出了所有努力
- python - 无法从 anaconda navigator 启动 jupyter notebook 或 spyder
- python - Kivy 按钮和变量的问题
- nginx - 告诉 Nginx 在不同的目录中查找我的主题文件
- django - Django 遍历 Queryset 并获取用户输入
- react-native - 为什么我的应用程序停止发出 api 请求?
- azure - 如何在 Azure 管道运行期间检索 VsTest 测试计划测试用例 ID 并在自动化代码中使用它
- c# - C# UWP Richeditbox 缩放内容有问题
- javascript - MS Access - 按钮“添加”上的 2021 语法错误