Last active
June 2, 2016 16:33
-
-
Save kellan/f30b1cee935b0575ab3f1491fd16e008 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
update_expression, update_expression_names, update_values = generate_update(item) | |
resp = table.update_item( | |
Key=key, | |
UpdateExpression=update_expression, | |
ExpressionAttributeNames=update_expression_names, | |
ExpressionAttributeValues=update_values) | |
print(resp) | |
def generate_update(item): | |
update_expression = ["#{}=:{}".format(k,k) for k in item] | |
update_expression = "set " + ', '.join(update_expression) | |
update_expression_names = {"#{}".format(k):k for k in item} | |
update_values = {":{}".format(k):item[k] for k in item} | |
return update_expression, update_expression_names, update_values |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment