python - 为什么这个 Python 函数不返回 future ?

标签 python google-app-engine

我将 Google App Engine 与 NDB 结合使用。为了简洁起见,我删除了很多代码,但保留了基本问题。我遇到错误 'list' object has no attribute 'get_result'

def get_future(keys):
    future = ndb.get_multi_async(keys)
    important_value = ... # get important value
    return {"future" : future, "value" : important_value}

dic = get_future(keys)
future = dic['future']
# error `'list' object has no attribute 'get_result'`
items = future.get_result()

为什么我应该得到一个 future 却得到一个列表?

最佳答案

get_multi_async 实际上返回 future 对象的列表,因此您需要对这些对象调用 .get_result()

Official definition :

ndb.get_multi_async(keys, **ctx_options)

Asynchronously fetches entities identified by the passed sequence of keys.

Arguments

keys
 -Sequence of keys

**ctx_options 
 -Context options 

Returns a list of Future objects. Each future's result is a Model instance or None if the key wasn't found.

关于python - 为什么这个 Python 函数不返回 future ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13150592/

相关文章:

android - Qpython3 的 lxml(Android 上的 Python3)

python - Pywikibot 登录 SSLError 185090050

python - regexp_tokenize 和阿拉伯文本

javascript - Google Closure 编译器以不同的编码返回?

google-app-engine - GAE Golang - OAuth 和 OAuth2?

python - 从字节变量设置 Kivy 图像

python - sympy如何将ln((exp(x)+1)/exp(x))简化为log(1+exp(-x))?

google-app-engine - 使用 dispatch.xml 在自定义域下路由非默认模块的根

node.js - 我可以浏览 node.js 项目的本地 Google Datastore 模拟器数据吗?

google-app-engine - Golang/App Engine - 安全地散列用户密码