试图从名为dow
的变量向weekdays:[0]
添加值。在
create_data = {"startDateTime":"2015-02-23T09:05:00-0600","endDateTime":"2015-02-23T10:05:00-0600","accessories":[],"customAttributes":[{"attributeId":"3","attributeValue":""},{"attributeId":"5","attributeValue":"Yes"}],"description":"Placeholder Description","invitees":[],"participants":[],"recurrenceRule":[{"type":"weekly","interval":2,"weekdays":[0],"repeatTerminationDate":"2015-05-24T09:50:00-0600"}],"resourceId":"15","resources":["15"],"title":"","userId":"26","startReminder":"","endReminder":""}
我搞不清是在词典中添加还是在列表中添加。在
尝试了以下方法,但却产生了以下错误:
^{pr2}$以下是错误。在
Traceback (most recent call last):
File "api.py", line 51, in <module>
create_data['recurrenceRule']['weekdays'] = dow
TypeError: list indices must be integers, not str
如何访问该值?在
create_data
是一个字典,recurrenceRule
是它的键之一。然后,它的值是一个列表:因此,要更改
^{pr2}$weekdays
,首先必须访问列表中的第一个元素:这就是为什么会出现这样的错误:
因为您正试图使用字符串访问列表的索引(0、1、2…)。在
create_data['recurrenceRule']
的值是list,list包含dictionary As item。因此我们必须从列表中获取项,即字典,并在其中添加weekdays
键。在相关问题 更多 >
编程相关推荐