我使用的一般结构如下所示:
worklist = [...]batchsize = 500for i in xrange(0, len(worklist), batchsize): batch = worklist[i:i+batchsize] # the result might be shorter than batchsize at the end # do stuff with batch
请注意,我们使用
step参数
xrange来大大简化批处理。

我使用的一般结构如下所示:
worklist = [...]batchsize = 500for i in xrange(0, len(worklist), batchsize): batch = worklist[i:i+batchsize] # the result might be shorter than batchsize at the end # do stuff with batch
请注意,我们使用
step参数
xrange来大大简化批处理。