[Python-Dev] Proposed iterator representations (original) (raw)

Armin Rigo arigo at tunes.org
Sat Apr 10 07:22:17 EDT 2004


Hello Raymond,

On Thu, Apr 08, 2004 at 10:37:18PM -0400, Raymond Hettinger wrote:

I checked in two itertool representations that were clear-cut:

>>> from itertools import count, repeat >>> count(20) count(20) >>> repeat(None, 12) repeat(None, 12)

Another point of view is that these representation are not very informative if you don't already know count() and repeat(): someone will probably type the above code in order to experiment with them, and the repr doesn't help in this respect. I think I'd prefer a more standard representation for all the iterators for which it is reasonably possible to do so.

count(20) <itertools.count: 20, 21, 22, ...> repeat(None, 12) <itertools.repeat: None, None, None, ... 12 elements> iter(xrange(10, 20, 2)) <rangeiterator: 10, 12, 14, ... 5 elements>

A bit of effort should be made at showing the nicest answer, e.g.:

iter(xrange(0)) <rangeiterator: empty> iter(xrange(1)) <rangeiterator: 0> iter(xrange(2)) <rangeiterator: 0, 1> iter(xrange(3)) <rangeiterator: 0, 1, 2> iter(xrange(4)) <rangeiterator: 0, 1, 2, 3> iter(xrange(5)) <rangeiterator: 0, 1, 2, ... 5 elements>

Armin



More information about the Python-Dev mailing list