Please see the end of the mail for the important point !!! Eric Firing wrote: > Manuel, > > Although it doesn't hurt, I don't think it is worthwhile changing range > to xrange. From the 2.5 docs: [...snip...] > Note "minimal" advantage. xrange was intended for special-case use, not > general use.
Eric, yes, I absolutely agree with you that this is only a small (minimal) advantage, probably not worth to worry about. Nevertheless ... > And from Python 3.0, http://docs.python.org/dev/3.0/whatsnew/3.0.html > xrange() renamed to range(), so range() will no longer produce a list > but an iterable yielding integers when iterated over. Python 3.0 will use xrange() by default, but it is then named range(), so from that _I_ conclude that xrange() should be used by default. You can also see the difference by using 2to3: """ for i in range(10): print i for i in xrange(10): print i """ gets converted to: """ for i in range(10): print i for i in range(10): print i """ That is, because 2to3 is a clever program. But: """ a = range(10) b = xrange(10) for i in a: print i for i in b: print i """ gets converted to """ a = list(range(10)) b = range(10) for i in a: print(i) for i in b: print(i) """ ;-) As you said, it's only a minimal advantage and 2to3 is a clever code!!! (THE IMPORTANT POINT) But this brings me to another, more important point: In the axes hist() method, a keyword named "range" is used that is passed to the numpy histogram() function, which has the kwarg 'range'. Now, this is not a problem as long as the range() builtin function is not used in the hist() method. But there are a few loops in this method that use xrange(), so this code will be translated to range() in py3 -- and that will be a problem. A basic example with a pseudo-code: """ def foo(x, range=(1,10)): print range for i in xrange(x): print i foo(10) """ with 2to3 --> """ def foo(x, range=(1,10)): print(range) for i in range(x): print(i) foo(10) """ which then fails. One solution would be to use a different keyword argument, maybe "binrange" instead of "range" and to throw a deprecated warning for the old keyword ??? Manuel > This implies to me that range is the preferred form, and xrange is > intended to go away. > > Eric > [...snip...] ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ Matplotlib-devel mailing list Matplotlib-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-devel