python - 为什么我得到对象不可调用?
问题描述
编码:
import json
data=json.load(open("data.json"))
print(data)
data("rain")
给我一个错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module> TypeError: 'dict' object is not callable
解决方案
您的 Pythondict
语法已关闭。假设您要访问 的rain
密钥data
,则必须使用[]
运算符。
import json
data=json.load(open("data.json"))
print(data)
data["rain"] # <--- change this
Python 认为您正在调用一个函数(使用()
),因此告诉您不能将字典作为函数调用!
推荐阅读
- python - 将 pandas 数据框中的列表传递给 sklearn 以用于 TF IDF
- python - 如何在 python 中使用 Selenium 获取价格?
- javascript - 如何阻止父 div 拉伸到子 div 的高度?
- sql - 如何获得 2 列中的小时、分钟和秒的总和?
- google-app-engine - gcloud app部署错误需要“vpcaccess.connectors.use”权限
- java - 如何在Java中调用对象的名称?
- postgresql - 创建新表与在 psql 中保留字段之间的区别
- ocaml - 为什么我的“地图”处理元素的实现顺序相反?
- r - R中“子集”函数的逻辑参数到底是什么?
- android - 如何在jetpack compose中为每个语言环境设置特定的字体系列