我将 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()
。
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/