[Python-Dev] _length_cue()

Nick Coghlan ncoghlan at gmail.com
Fri Feb 10 14:44:45 CET 2006

Armin Rigo wrote:
> Hi Nick,
> On Fri, Feb 10, 2006 at 11:21:52PM +1000, Nick Coghlan wrote:
>> Do they really need anything more sophisticated than:
>>    def __repr__(self):
>>      return "%s(%r)" % (type(self).__name__, self._subiter)
>> (modulo changes in the format of arguments, naturally. This simple one would 
>> work for things like enumerate and reversed, though)
> My goal here is not primarily to help debugging, but to help playing
> around at the interactive command-line.  Python's command-line should
> not be dismissed as "useless for real programmers"; I definitely use it
> all the time to try things out.  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
>>>> enumerate("spam")
> enumerate("spam")          # with your proposed extension -- not better
> However, if this kind of goal is considered "not serious enough" for
> adding a private special method, then I'm fine with trying out a fishing
> approach.

Ah, I see the use case now. You're right in thinking I was mainly considering 
the debugging element (and supporting even that would be an improvement on the 
current repr methods, which are just the 'type with instance ID' default repr).

In terms of "what does it do" though, I'd tend to actually iterate the thing:

Py> for x in enumerate("spam"): print x
(0, 's')
(1, 'p')
(2, 'a')
(3, 'm')


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-Dev mailing list