[Greg Ewing] > pinard@iro.umontreal.ca: > > could we have the guarantee that if an iterable returns an > > iterator through the iterable's __iter__, the iterator's __iter__ method > > will never be called from looping over the iterable? > [...pause while Greg's brain parses that sentence...] (Sorry for my bad English.) > Yes, I believe that's true. If yes, then, the Library Reference is misleading, at the page: http://www.python.org/dev/doc/devel/lib/typeiter.html when it strongly says that any iterator's __iter__ method is "required". I guess this is a possible source of confusion. The context does not make it clear that the iterator's __iter__ method is *only* required whenever one *also* wants to use an iterator as an iterable. Better would be to describe __iter__ only once, the first time through, saying everything there that has to be said, and only retain for iterators the requirement of having a `next()' method. We should describe the truth. P.S. - Also, I do not understand the tiny bit about the `in' statement in the above page. Has `in' ever been a statement? If it refers to the comparison operator `in', then has it any special properties when used with iterators? I'm unsuccessful at seeing any hint about this from the documentation: http://www.python.org/dev/doc/devel/ref/comparisons.html -- François Pinard http://www.iro.umontreal.ca/~pinard
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4