【问题标题】:How to get datastore name/id column value如何获取数据存储名称/id 列值
【发布时间】:2019-03-11 05:06:36
【问题描述】:

我正在尝试使用下面的 next(iter(result)) 获取数据存储类型实体的名称/id 列值,但正在寻找其他方法。我试过这种方式 result[0]['id'] 但它不起作用。有什么建议吗?

    query = self.ds.query(kind=self.__tablename__)
    query.add_filter('email', '=', self.email)
    result = query.fetch(1)
    id = next(iter(result))

【问题讨论】:

  • 使用next(iter(result))有什么问题?

标签: python google-app-engine google-cloud-datastore


【解决方案1】:

数据存储实体的键是不属于属性字典的特殊属性。

https://googleapis.github.io/google-cloud-python/latest/datastore/entities.html 中所述,您可以通过在实体本身上调用id 来获取ID。所以list(result)[0].idlist(result)[0].key.id

【讨论】:

    猜你喜欢
    • 2011-11-13
    • 2021-09-13
    • 2020-01-14
    • 2016-03-28
    • 1970-01-01
    • 1970-01-01
    • 2021-01-08
    • 2021-11-26
    • 1970-01-01
    相关资源
    最近更新 更多