On Wed, 16 Apr 2008, David Wolever wrote: > On 16-Apr-08, at 9:37 AM, Isaac Morland wrote: >> On Wed, 16 Apr 2008, Paul Moore wrote: >>> On 16/04/2008, Armin Rigo <[EMAIL PROTECTED]> wrote: >>>> What about the less confusing and more readily generalizable: >>>> <range object 0, 1, ..., 9> >>>> >>>> It would also be helpful IMHO to use this kind of repr for most built-in >>>> iterators and iterables, instead of their mosty-useless default repr. >>> >>> I quite like this. But as a non-beginner, I'll freely admit that my >>> intuitions are suspect :-) >> >> I like this too. For iterators, though, would you always show the next >> couple of elements? The values "contained in" the iterator will change as >> the iterator iterates. Alternatively, the representation could be >> "frozen" to reflect the values originally pending in the iterator, but >> then the representation wouldn't show anything about the current state of >> the iterator. > So would you mean something like: > <generator object <__main__.Foo instance at 0x835d0>, <__main__.Foo instance > at 0x83620>, ...> > Or maybe: > <generator <__main__.Foo instance at 0x835d0>, <__main__.Foo instance at > 0x83620>, ... > > > While I agree in theory, I'm not sure I like the looks of it in practise.
I was mostly responding to what I saw as a suggestion to change the representation of existing iterators. It's been pointed out in a previous reply to my message that obtaining values from a general iterator for use in the representation is problematic at best, and in general I don't think it can be done in an acceptable fashion, because I can imagine code depending on values not being obtained from an iterator before they are explicitly requested by next(). We wouldn't want a call to __repr__() to change the operation of the iterator, so any idea to pull two values and store them somewhere isn't generally acceptable. For some specific iterators which have access to all the underlying information, an informative representation is possible and frequently feasible. My question simply concerned what it would look like. Would it show the next couple of items, or the first couple of items (or something else)? Isaac Morland CSCF Web Guru DC 2554C, x36650 WWW Software Specialist _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com