Why not just use: for idx in range(options.from_id, options.to_id + 1)?