从 google 数据存储 python 的列表中检索值
Retrieve value from list from google datastore python
我在 python 中有一个列表,它是对 Google 的数据存储区的查询结果,该列表如下所示:
[<Entity('User', 1111) {'refreshToken': 'xxx', 'firstName': 'Bill', 'lastName': 'Last', 'accessToken': 'xxx', 'idToken': 'xxx', 'email': 'the_email'}>]
我需要提取 1111
实体的 ID。到目前为止,我尝试了以下但没有成功:
result = list(query.fetch())
print(result[0][0]) #fails
print(result[0].Entity) #fails
print(result[0]['User']) #fails
print(result['User']) #fails
知道如何检索 ID 值吗?
entity = result[0]
print(entity.id)
当您通过提取查询取回实体对象时。您可以像字典一样访问信息。
# the line that said print(result["User"]) works
# the problem is that the key you used may not be the exact wording as in the data store entity
entity = list(query.fetch())[0]
print(entity['user']) #works just be careful for the key you pass in the []
我在 python 中有一个列表,它是对 Google 的数据存储区的查询结果,该列表如下所示:
[<Entity('User', 1111) {'refreshToken': 'xxx', 'firstName': 'Bill', 'lastName': 'Last', 'accessToken': 'xxx', 'idToken': 'xxx', 'email': 'the_email'}>]
我需要提取 1111
实体的 ID。到目前为止,我尝试了以下但没有成功:
result = list(query.fetch())
print(result[0][0]) #fails
print(result[0].Entity) #fails
print(result[0]['User']) #fails
print(result['User']) #fails
知道如何检索 ID 值吗?
entity = result[0]
print(entity.id)
当您通过提取查询取回实体对象时。您可以像字典一样访问信息。
# the line that said print(result["User"]) works
# the problem is that the key you used may not be the exact wording as in the data store entity
entity = list(query.fetch())[0]
print(entity['user']) #works just be careful for the key you pass in the []