[Python-Dev] printing xrange objects (original) (raw)

Fred L. Drake, Jr. fdrake@beopen.com
Thu, 3 Aug 2000 11:48:28 -0400 (EDT)


Thomas Wouters writes:

Sorry, my bad. I just did 'x', and assumed it called repr(). I guess my newbiehood shows in that I thought 'print x' always called 'str(x)'. Like I

That's the evil beauty of tp_print -- nobody really expects it because most types don't implement it (and don't need to); I seem to recall Guido saying it was a performance issue for certain types, but don't recall the specifics.

Why not remove the first and last argument, if they are respectively 0 and 1?

I agree! In fact, always removing the last argument if it == 1 is a good idea as well. Here's the output from the current patch:

xrange(2) xrange(2) xrange(2, 4) xrange(2, 4) x = xrange(10, 4, -1) x xrange(10, 4, -1) x.tolist() [10, 9, 8, 7, 6, 5] x*3 (xrange(10, 4, -1) * 3)

-Fred

-- Fred L. Drake, Jr. BeOpen PythonLabs Team Member