I wrote a script which I wanted to enable for both Python 2 and Python 3.
After importing division
and print_function
from __future__
, my only concern was that my range
returns a whole array in Python 2, wasting time and memory.
I added the following 3 lines at the beginning of the script, as a workaround:
if sys.version_info[0] == 3:
def xrange(i):
return range(i)
Then, I only used xrange
in my code.
Is there some more elegant way to do it rather than my workaround?