I wrote a script that I wanted to include for both Python 2 and Python 3.
After importing to divisionand print_functionfrom, __future__my only problem was that mine was rangereturning an entire 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 used xrangein my code.
Is there an even more elegant way to do this, and not my workaround?
source
share