是否有一种优雅的分页方式boto.resultset.ResultSet
,例如:
amt = boto.mturk.connection.MTurkConnection()
qualid = "XXX"
quals = amt.get_qualifications_for_qualification_type( qualid, page_size=100, page_number=1 )
# quals becomes boto.resultset.ResultSet with just 100 items
最后一个查询可以返回多页结果。鉴于boto
中有很多查询返回几页结果,是不是有任何优雅的方法来迭代所有结果?
答案 0 :(得分:0)
好吧,我正在使用自己的解决方案:
def get_entire_resultset( query, *args, **kargs ):
ps = 100; pn = 1
objs = query( *args, page_size=ps, page_number=pn, **kargs )
total_downloaded = ps
pn += 1
total = int(objs.TotalNumResults)
while total_downloaded<total:
objs.extend( query( *args, page_size=ps, page_number=pn, **kargs ) )
total_downloaded += ps
pn += 1
return objs
使用如下:
quals = get_entire_resultset( amt.get_qualifications_for_qualification_type, qualid )