我正在尝试编写一个python脚本,从json文件读取数据,对其进行一些计算,然后将输出写入一个新的json文件。但我似乎无法自动执行json读取过程。我知道这个错误。你能帮我解决这个问题吗?
非常感谢你
print([a[0]][b[1]][c[1]])
TypeError: list indices must be integers or slices, not str
杰森
{
"male": {
"jack": {
"id": "001",
"telephone": "+31 2225 345",
"address": "10 Street, Aukland",
"balance": "1500"
},
"john": {
"id": "002",
"telephone": "+31 6542 365",
"address": "Main street, Hanota",
"balance": "2500"
}
},
"female": {
"kay": {
"id": "00",
"telephone": "+31 6542 365",
"address": "Main street, Kiro",
"balance": "500"
}
}
}
Py
with open("q.json") as datafile:
data = json.load(datafile)
a = ['male', 'female']
b = ['jack', 'john', 'kay']
c = ['id', 'telephone', 'address', 'balance']
print([a[1]][b[1]][c[1]])