Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 应用程序引擎查询使用索引引用检索数据_Python_Google App Engine_Gql - Fatal编程技术网

Python 应用程序引擎查询使用索引引用检索数据

Python 应用程序引擎查询使用索引引用检索数据,python,google-app-engine,gql,Python,Google App Engine,Gql,例如,有没有方法将索引作为数组引用到结果条目 class Entry(Base): amount = db.IntegerProperty() entries = Entry.gql("WHERE amount > 0") 您必须执行fetch()。这将为您提供一个条目列表。在这种情况下,my_entry=entries[4]将为您提供第五个对象。您试图做的是操纵gql对象。这显然行不通。试试这个 my_entry = entries[4] 您可以在查询实例上使用该方法: cl

例如,有没有方法将索引作为数组引用到结果条目


class Entry(Base):
    amount = db.IntegerProperty()


entries = Entry.gql("WHERE amount > 0")
您必须执行fetch()。这将为您提供一个条目列表。在这种情况下,my_entry=entries[4]将为您提供第五个对象。您试图做的是操纵gql对象。这显然行不通。试试这个

my_entry = entries[4]
您可以在
查询
实例上使用该方法:

class Entry(Base):
    amount = db.IntegerProperty()


entries = Entry.gql("WHERE amount > 0").fetch(1000)

print entries[4].amount

entries=[Entry.gql中的x代表x(“其中金额>0”)]


此答案与之前答案的区别在于,它在数据存储中而不是在处理程序中进行过滤,并且不需要猜测将返回的实体的最大数量。

如果要在结果查询中引用特定索引的一个对象,您可以使用
db的
fetch
方法。使用
offset
参数查询

entries= [entry for entry from Entry.all() if entry.amount > 0]
print entries[4]
但是,如果要引用查询结果中的多个对象,
fetch
all并作为普通Python数组索引:

entry = Entry.gql("WHERE amount > 0").fetch(1, offset=4)[0]
print entry.amount

您可以简单地使用
list(Entry.gql(“WHERE amount>0”)
。这两种方法的效率都低于对查询调用
.fetch(n)
,其中n是所需结果的最大数量。这将返回数据存储中的所有记录,并且不会扩展。
entry = Entry.gql("WHERE amount > 0").fetch(1, offset=4)[0]
print entry.amount
entries = Entry.gql("WHERE amount > 0").fetch(1000)
print entries[4].amount
print entries[5].amount
print entries[7].amount
# etc.