我试图将记录插入表中,但是只有循环中的最后一条记录(结果数据)才插入表中
这是我尝试的代码:
fields
没弄错我在哪里
答案 0 :(得分:0)
您在循环外分配了ResultData
并在每次循环运行时更改了相同键的值。试试这个:
CDates = ['2020-05-10', '2020-05-12', '2020-05-13', '2020-05-16', '2020-05-20']
for date in CDates:
filterDate = Key('Date').eq(id)
appResponse = appTable.scan(FilterExpression=filterDate)
accResp = table.query(
KeyConditionExpression=Key('PrimaryId').eq('Key'),
FilterExpression=Key('Date').eq(date))
if len(accResp['Items']) == 0:
ResultData = {
'PrimaryId': 'Key',
'CreationDate': date,
'Type': 'Appt',
'Id': str(uuid.uuid4())
}
print(ResultData)
table.put_item(Item=ResultData)