Steven D'Aprano <steve+pyt...@pearwood.info> added the comment: On Sun, Nov 18, 2018 at 10:27:11PM +0000, Julien Palard wrote: > > Julien Palard <julien+pyt...@palard.fr> added the comment: > > If I understand correctly, you'd like str(range(10)) to return "<range object > [1, 2, ..., 8, 9]>"?
Exactly the same as you suggested for repr(range(10)) to return, so yes. > I'm really unconfortable doing this, for me __str__ is here to return > an “informal or nicely printable string representation of an object", I think that the output you suggested is an informal AND nicely printable string representation of the object. In what way do you think it fails? It's an *informal* representation in the sense that it doesn't mimic the range constructor, you can't evaluate it, it isn't even legal Python syntax. "Nicely printable" is a matter of taste, but I think its quite nice (just not suitable for use as the repr), and especially nice for the purpose of showing the kind of object we're dealing with, rather than just the values in it. > not a convoluted "<{type(object)} object ...>" notation. If this is too convoluted for str(), why is it suitable for beginners when it goes through repr() instead? > I agree with you, the [0, 1, ..., 8, 9] notation is too confusing with > the repr of a list, that's why I proposed the "0, 1, ..., 8, 9" which > looks nice. Except that it gives no clue that it is a range object, and fails for empty ranges. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue35200> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com