l = range(int(1E9))

Chris Angelico rosuav at gmail.com
Sun May 3 07:29:21 EDT 2015


On Sun, May 3, 2015 at 9:15 PM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> Or if you prefer:
>
> try:
>     range = xrange
> except NameError:
>     pass
>
> and just use range.

I prefer this idiom, on the basis that code should be written for the
more recent version, and have minimal code to support older versions.
Then when you drop support for the older versions, all you have to do
is delete a bit at the top. The same principle applies to the
__future__ import system - you can declare that your Python 2.5 code
is able to use the 'with' statement, but you can't (and shouldn't)
make your 2.6+ code use 'with' as a name.

ChrisA



More information about the Python-list mailing list