"Steven Bethard" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
Probably you want to catch a TypeError instead of an AttributeError; objects may support the iterator protocol without defining an __iter__ method:
No, having an __iter__ method that returns an iterator is an essential half of the current iterator protocol just so that iter(iterator) (== iterator.__iter__()) always works. This requirement conveniently makes 'iterator' a subcategory of 'iterable'.
Yeah, you're right, I probably should have referred to it as the 'iterable protocol' instead of the 'iterator protocol'.
> (I am ignoing the old and obsolete > getnext protocol, as does the itertools library module.)
What is the getnext protocol? Is that the same thing that the iter() docs call the sequence protocol? Because this definitely still works with itertools:
>>> class C: ... def __getitem__(self, index): ... if index > 3: ... raise IndexError(index) ... return index ... >>> import itertools >>> list(itertools.imap(str, C())) ['0', '1', '2', '3']
Steve -- http://mail.python.org/mailman/listinfo/python-list