This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author steven.daprano
Recipients mdk, ncoghlan, rhettinger, seluj78, serhiy.storchaka, steven.daprano
Date 2018-11-19.09:26:00
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <20181119085943.GB11582@ando.pearwood.info>
In-reply-to <1542580031.09.0.788709270274.issue35200@psf.upfronthosting.co.za>
Content
On Sun, Nov 18, 2018 at 10:27:11PM +0000, Julien Palard wrote:
> 
> Julien Palard <julien+python@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.
History
Date User Action Args
2018-11-19 09:26:01steven.dapranosetrecipients: + steven.daprano, rhettinger, ncoghlan, serhiy.storchaka, mdk, seluj78
2018-11-19 09:26:01steven.dapranolinkissue35200 messages
2018-11-19 09:26:00steven.dapranocreate