【问题标题】:How to access properties of Datastore query (App Engine, python)如何访问数据存储区查询的属性(App Engine、python)
【发布时间】:2020-08-05 22:30:21
【问题描述】:

我在尝试访问数据存储区查询的属性时发疯了。我在文档中找不到任何东西(可能是我)。

在数据存储中,我有以下内容:

这是我的 main.py 的 sn-p:

import all the necessary stuff
...
datastore_client = datastore.Client()
u_name = 'batman' # example of the user I want to find
qn = datastore_client.query(kind='user').add_filter('user_id', '=', u_name).fetch()

到目前为止一切顺利,但如何访问此查询的属性?

我找不到的是如何访问用户“batman”的名字? 比如:

name = qn.somefuntion('first_name')

有人能告诉我如何做到这一点,并指出相应的文档吗?

谢谢!

【问题讨论】:

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


    【解决方案1】:

    查看python library reference for an Entity。关键部分是“您可以将实体视为常规 Python 字典。”

    for entity in qn:
        print(entity['first_name'])
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-08-16
      • 1970-01-01
      • 2013-05-17
      • 1970-01-01
      • 1970-01-01
      • 2015-04-19
      • 1970-01-01
      相关资源
      最近更新 更多