<div dir="ltr">On 21 September 2013 09:48, Terry Reedy <span dir="ltr"><<a href="mailto:tjreedy@udel.edu" target="_blank">tjreedy@udel.edu</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On 9/20/2013 6:00 PM, Tim Delaney wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I think there is a distinction here between collections.Iterable (as a<br>
defined ABC) and something that is "iterable" (lowercase "i"). As you've<br>
noted, an "iterable" is "An object capable of returning its members one<br>
at a time".<br>
<br>
So I think a valid definition of reiterable (barring pathological cases) is:<br>
<br>
     obj is not iter(obj)<br>
</blockquote>
<br></div>
If obj has a fake __getitem__, that will not work.<br>
<br>
class Cnt:<br>
    def __init__(self, maxn):<br>
        self.n = 0<br>
        self.maxn = maxn<br>
    def __getitem__(self, dummy):<br>
        n = self.n + 1<br>
        if n <= self.maxn:<br>
            self.n = n<br>
            return n<br>
        else:<br>
            raise IndexError<br>
<br>
c3 = Cnt(3)<br>
print(c3 is not iter(c3), list(c3), list(c3))<br>
>>><br>
True [1, 2, 3] []<br>
<br>
Dismissing legal code as 'pathological', as more than one person has, does not cut it as a design principle.</blockquote><div><br></div><div>To me, that is a reiterable. It might not give the same results each time through, but you can iterate, it stops, then you can iterate over it again - it won't raise an exception trying to do so. So not what I would consider a pathological case - though definitely an unusual case and one that obviously wouldn't work in many situations that require reiterables to return the same values in the same order each time through.</div>
<div><br></div><div>So we've got two classes of reiterables here</div><div><br></div><div>- anything that can be iterated through, and then iterated through again, for which obj is not iter(obj) will work in all but what I consider to be pathological cases;</div>
<div><br></div><div>- iterables that can be iterated through multiple times, returning the same objects in the same order each time through, for which I don't think a test is possible.</div><div><br></div><div>Tim Delaney </div>
</div></div></div>