我有一个movie_data.json
文件。我想读取json
文件并将99popularity
更改为popularity
[
{
"99popularity": 83.0,
"director": "Victor Fleming",
"genre": [
"Adventure",
" Family",
" Fantasy",
" Musical"
],
"imdb_score": 8.3,
"name": "The Wizard of Oz"
},
{
"99popularity": 88.0,
"director": "George Lucas",
"genre": [
"Action",
" Adventure",
" Fantasy",
" Sci-Fi"
],
"imdb_score": 8.8,
"name": "Star Wars"
},
]
我试图读取json文件
import json
with open('movie_data.json') as f:
data = json.load(f)
print(data['director'])
它给了我一个错误-
Traceback (most recent call last):
File "json-read.py", line 6, in <module>
print(data['director'])
TypeError: list indices must be integers or slices, not str
加载到文件中,然后可以使用
pop
属性交换密钥:相关问题 更多 >
编程相关推荐