[Python-ideas] Enhancing range object string displays
Steven D'Aprano
steve at pearwood.info
Mon Nov 19 19:19:51 EST 2018
On the bug tracker, there is a proposal to enhance range objects so that
printing them will display a snapshot of the values included, including
the end points. For example:
print(range(10))
currently displays "range(10)". The proposal is for the __str__ method
to instead return "<range object [0, 1, ..., 8, 9]>".
https://bugs.python.org/issue35200
print(range(2, 200, 3)) would display
<range object [2, 5, ..., 194, 197]>
Note that the original proposal was for range objects' __repr__ to
display this behaviour. But given the loss of eval(repr(obj)) round
tripping, and the risk of breaking backwards compatibility, it was
decided that isn't acceptable but using the same display for __str__
(and hence produced by print) would be nearly as useful but without the
downsides.
The developer who proposed the feature, Julien, now wants to reject the
feature request. I think it is still a useful feature for range objects.
What do others think? Is this worth re-opening?
--
Steve
More information about the Python-ideas
mailing list