AttributeError: 'dynamodb.Table' object has no attribute 'primary_key'
AttributeError: 'dynamodb.Table' object has no attribute 'primary_key'
这是一个微不足道的问题,但我没有找到关于如何从 AWS 中的 dynamoDB table 获取 primary
的答案。
(我知道我们可以从 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"]
这是一个微不足道的问题,但我没有找到关于如何从 AWS 中的 dynamoDB table 获取 primary
的答案。
(我知道我们可以从 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"]