这是一个微不足道的问题,但我没有找到有关如何primary
从AWS 的 dynamoDB 表中获取的答案。(我知道我们可以从dynamodb
对象中获取,但我想直接从dynamodb.Table
.
问题: AttributeError: 'dynamodb.Table' object has no attribute 'primary_key'
解决方案:像my_table.get_primary_key()
?
这是一个微不足道的问题,但我没有找到有关如何primary
从AWS 的 dynamoDB 表中获取的答案。(我知道我们可以从dynamodb
对象中获取,但我想直接从dynamodb.Table
.
问题: AttributeError: 'dynamodb.Table' object has no attribute 'primary_key'
解决方案:像my_table.get_primary_key()
?
import inspect
print(inspect.getmembers(table, lambda a: not (inspect.isroutine(a))))
结果:
[....('attribute_definitions', [{'AttributeName': 'mail', 'AttributeType': 'S'}]), ...]
答案::
def get_primary_key(table):
return table.attribute_definitions[0]["'AttributeName"]