Python 光标是如何工作的?

Python 光标是如何工作的?,python,Python,我有以下代码 def get(self): date = datetime.date.today() loc_query = Location.all() last_cursor = memcache.get('location_cursor') if last_cursor: loc_query.with_cursor(last_cursor) loc_result = loc_query.fetch(1) for loc in loc_re

我有以下代码

def get(self):
    date = datetime.date.today()
    loc_query = Location.all()

    last_cursor = memcache.get('location_cursor')
    if last_cursor: loc_query.with_cursor(last_cursor)
    loc_result = loc_query.fetch(1)

    for loc in loc_result:
        self.record(loc, date)
        taskqueue.add(
            url='/task/query/simplegeo',
            params={'date':date, 'locid':loc.key().id()}
        )

    if len(loc_result):
        memcache.add('location_cursor', loc_query.cursor())
        taskqueue.add(url='/task/count/', method='GET')
    else:
        memcache.add('location_cursor', None)

我不知道我做错了什么,但我得到了相同的光标,这不是我想要的效果。光标为什么不移动?

您误用了
memcache.add
,其文档记录如下:

设置键的值,当且仅当 项不在memcache中

因此,您永远不会存储与第一个不同的游标。使用
memcache.set
代替

设置键的值,而不考虑 缓存中以前的内容


请注意,这与游标无关——这都是关于正确使用
memcache

您误用了
memcache.add
,其记录如下:

设置键的值,当且仅当 项不在memcache中

因此,您永远不会存储与第一个不同的游标。使用
memcache.set
代替

设置键的值,而不考虑 缓存中以前的内容

请注意,这与游标无关——这都是关于正确使用
memcache