l = range(int(1E9))

Steven D'Aprano steve+comp.lang.python at pearwood.info
Sun May 3 07:15:40 EDT 2015


On Sun, 3 May 2015 08:33 am, BartC wrote:

> OK, so it's just an irritation then, as a workaround has been available
> for a long time. (For example, if you use xrange, it won't work on 3.x.
> If you use range, then it might be inefficient on 2.x.)


That is trivially easy to deal with. Put this at the top of your module:

try:
    xrange
except NameError:
    xrange = range


and then use xrange throughout the module. Or if you prefer:

try:
    range = xrange
except NameError:
    pass

and just use range.


-- 
Steven




More information about the Python-list mailing list