到python的分页
题
所有,
这可能是一个漂亮的新手问题,但我陷入了如何在Python中执行此操作。我需要做的是,在从Panaramio请求数据时设置往返和从参数。
http://www.panoramio.com/map/get_panoramas.php? set= public& from= 0&to= 100 &minx= -180&miny= -90&maxx= 180&maxy= 90&size= sible&mapfilter= true
panoramio只允许您一次返回100个记录,因此我需要构建URL字符串以显示100个设置的前进。 101-200,201-300等是否有一个例子,可以向我展示如何使用Python进行这种类型的分页?
谢谢, adam
更新:
以下示例似乎做了我想要的事情。现在我必须弄清楚如何从101-200,201,300等开始,从那里可以采用这些值并构建我的查询字符串。这是有意义的吗?
.
def counter(low, high):
current = low
while current <= high:
yield current
current += 100
if __name__ == '__main__':
for c in counter(100, 200):
print c
更新#2:我的情况越来越难,它应该是
.def counter(low, high):
while low <= high:
yield low, high
low += 100
high += 100
for i in counter(1, 100):
print i
解决方案
for number in range(1, 301, 100):
low = number
high = low + 100