[Python-Dev] string representation of range in 3.0

Brad Miller bonelake at gmail.com
Tue Apr 8 01:14:53 CEST 2008


I use Python in my CS1 and CS2 curriculum and I have a question.
As I've been using the Python 3.0 alphas one of the things that I am  
bothered by is that I cannot see the sequence produced by range  
without introducing students to the list() function.

I typically introduce range on day 1 of class and show students what  
it produces without making a big deal out of the fact that it creates  
a list.  They all accept this and things work out nicely when I  
introduce lists for real in a week or two.

My question is why couldn't the __str__ method for the range object be  
more friendly and show a representation of the sequence?  I understand  
why __repr__ should return range(0,10) for an object created using  
range(10) but couldn't print(range(10)) produce [0, 1, 2, ... 9]   
The ... could even be used if the sequence were excessively wrong.

If this is acceptable, I would be happy to accept the challenge of  
providing a patch.



More information about the Python-Dev mailing list