From 831103935be38d7734543742425099f1b9a551a7 Mon Sep 17 00:00:00 2001 From: Luong Anh Tuan Date: Wed, 12 Oct 2016 12:38:48 +0700 Subject: [PATCH] Remove xrange for run both Python 2 and Python 3 In python 3, range() does what xrange() used to do and xrange() does not exist. If you want to write code that will run on both Python 2 and Python 3, you can't use xrange(). range() can actually be faster in some cases - eg. if iterating over the same sequence multiple times. xrange() has to reconstruct the integer object every time, but range() will have real integer objects. (It will always perform worse in terms of memory however) xrange() isn't usable in all cases where a real list is needed. For instance, it doesn't support slices, or any list methods. Change-Id: I033289359882c08185d59d13fa0b994c4566185a --- library/dist_sort | 2 +- library/memcached | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/library/dist_sort b/library/dist_sort index d7a94c0..d2f38f2 100644 --- a/library/dist_sort +++ b/library/dist_sort @@ -118,7 +118,7 @@ class DistSort(object): src_list = self.params['src_list'].split(self.params['delimiter']) index += self.params['sort_modifier'] - for _ in xrange(index % len(src_list)): + for _ in range(index % len(src_list)): src_list.append(src_list.pop(0)) return self.params['delimiter'].join(src_list) diff --git a/library/memcached b/library/memcached index 5208fdd..919c53a 100644 --- a/library/memcached +++ b/library/memcached @@ -260,7 +260,7 @@ class Memcached(object): key_name = self.module.params['name'] get_keys = [ - '%s.%s' % (key_name, i) for i in xrange(MAX_MEMCACHED_CHUNKS) + '%s.%s' % (key_name, i) for i in range(MAX_MEMCACHED_CHUNKS) ] self.mc.delete_multi(get_keys) value = self.mc.get_multi(get_keys) @@ -419,7 +419,7 @@ class Memcached(object): key_name = self.module.params['name'] get_keys = [ - '%s.%s' % (key_name, i) for i in xrange(MAX_MEMCACHED_CHUNKS) + '%s.%s' % (key_name, i) for i in range(MAX_MEMCACHED_CHUNKS) ] multi_value = self.mc.get_multi(get_keys) if multi_value: