[Python-Dev] _length_cue()
Raymond Hettinger
python at rcn.com
Fri Feb 10 20:52:09 CET 2006
[Armin]
> It would be nicer if all these
> iterators I'm not familiar with would give me a hint about what they
> actually return, instead of:
>
>>>> itertools.count(17)
> count(17) # yes, thank you, not very helpful
I prefer that the repr() of count() be left alone. It follows the style
used by xrange() and other repr's that can be run through eval(). Also, the
existing repr keeps its information up-to-date to reflect the current state
of the iterator:
>>> it = count(10)
>>> it.next()
10
>>> it
count(11)
A good deal of thought and discussion went into these repr forms. See the
python-dev discussions in April 2004. Please don't randomly go in and
change those choices.
For most of the tools like enumerate(), there are very few assumptions you
can make about the input without actually running the iteration. So, I
don't see how you can change enumerate's repr method unless adopting a
combination of styles, switching back and forth depending on the input:
>>> enumerate('abcde')
<(0, 'a'), (1, 'b'), ...>
>>> enumerate(open('tmp.txt'))
<enumerate object at 0x00BFD800>
IMO, switching back and forth is an especially bad idea.
Hence, enumerate's repr ought to be left alone too.
Raymond
More information about the Python-Dev
mailing list