range() vs xrange() Python2|3 issues for performance

garabik-news-2005-05 at kassiopeia.juls.savba.sk garabik-news-2005-05 at kassiopeia.juls.savba.sk
Tue Aug 2 03:51:51 EDT 2011


harrismh777 <harmar at member.fsf.org> wrote:
 these will run on either Python2 or 
> Python3... except that if you substitute xrange() for range() for 
> Python2  they will throw an exception on Python3... doh.

if 'xrange' not in dir(__builtins__):
    xrange = range 

at the beginning of your program will fix that.

-- 
 -----------------------------------------------------------
| Radovan Garabík http://kassiopeia.juls.savba.sk/~garabik/ |
| __..--^^^--..__    garabik @ kassiopeia.juls.savba.sk     |
 -----------------------------------------------------------
Antivirus alert: file .signature infected by signature virus.
Hi! I'm a signature virus! Copy me into your signature file to help me spread!



More information about the Python-list mailing list