2024-09-28 21:35:50 发布
网友
我写的代码有问题。当我运行代码时,我得到一个错误:
Traceback (most recent call last): File "test23_json_users.py", line 23, in <module> for user_dict in abc['user_account']['sip_id']: TypeError: list indices must be integers, not str
代码:
abc['user_account']应该是一个列表。在
abc['user_account']
列表a=['hello',1,2,'people']有4个元素由索引a[0]到a[3]访问。在
a=['hello',1,2,'people']
a[0]
a[3]
字典d={'a':1,'b':2}有键和值。在本例中,d['a']的值为1,d[b']的值为2。在
d={'a':1,'b':2}
d['a']
d[b']
如果要访问abc['user_account']中的内容,请键入abc['user_account'][42]。如果你想迭代它
abc['user_account'][42]
for a in abc['user_account']: print a
改变
for user_dict in abc['user_account']['sip_id']:
到
abc['user_account']
应该是一个列表。在列表
a=['hello',1,2,'people']
有4个元素由索引a[0]
到a[3]
访问。在字典
d={'a':1,'b':2}
有键和值。在本例中,d['a']
的值为1,d[b']
的值为2。在如果要访问
abc['user_account']
中的内容,请键入abc['user_account'][42]
。如果你想迭代它改变
到
^{pr2}$相关问题 更多 >
编程相关推荐