如何使用python在dynamodb中追加一个列表数组

时间:2016-05-20 11:53:18

标签: python amazon-web-services amazon-dynamodb boto

我想使用python在dynamodb中附加一个数组列表。我正在使用boto。我能够在python中附加列表并将其保存在变量中。现在只想将该值附加到一个项目(数组列表)中,该项目现在是空的,并且不知道该怎么做。如果有人可以帮助我,那就太好了。

        result = self.User_Connection.scan(main_user__eq=self.username)
        for connection_details in result:
            main_user = connection_details['main_user']
            connection_list = connection_details['connections']
            connection_list.append(frnd_user_id)

我想将此 connection_list.append(frnd_user_id)添加为项目。 我试过这样做: -

        if user_connections['connections'] == None:
            self.User_Connection.put_item(data={'connections' : set(frnd_user_id)})
        else:
            self.User_Connection.update_item(Key = {user_connections['id']}, UpdateExpression="SET connections = list_append(connections, :i)",
                                             ExpressionAttributeValues={':i': [frnd_user_id],})

但它不起作用。给出错误: -

  

'表'没有属性' update_item'

我也尝试过这样做: -

result = self.User_Connection.scan(main_user__eq=self.username)
        for connection_details in result:
            main_user = connection_details['main_user']
            main_userid = connection_details['id']
            connection_list = connection_details['connections']
            print connection_list


            if connection_details['connections'] == None:

                self.User_Connection.put_item(data={'id' : main_userid,
                                                        'main_user':self.username,
                                                        'connections[]' : frnd_user_id})
            else:
                item = self.User_Connection.get_item(id = connection_details['id'])
                for i in frnd_user_id:
                    item[connection_list].append(i)
                item.save(overwrite=True)

这也显示错误。

  

不可用的类型:' list'

0 个答案:

没有答案