I got into a discussion about this, which made me think it would make sense to formalize a distinction between "iterable" and "iterator". To nearly any python developer I talk with, we can define them as:
iterable - An object which can be passed to the built-in iter() function, which returns an iterator.
iterator - An object with a .next() method, which is used to invoke the iteration. An iterator _should_ also be an iterable, and will nearly always return itself as its own iterator.
Now, the current documentation makes no distinction, and we see this in the docstring for iter(), which is curious:
iter(collection) -> iterator
This might indicate that it is using "collection" where I would say "iterable". Also, the same docstring makes mention of something being an iterator _or_ a sequence, so I also should bring up that it may be antiquated, yes?
-- Read my blog! I depend on your acceptance of my opinion! I am interesting! http://ironfroggy-code.blogspot.com/
Calvin Spealman wrote:
This might indicate that it is using "collection" where I would say "iterable". Also, the same docstring makes mention of something being an iterator _or_ a sequence, so I also should bring up that it may be antiquated, yes?
http://docs.python.org/dev/lib/typeiter.html
That page describes the same two categories you do, but doesn't actually use the word 'iterable' for the first category (i.e. anything with an __iter__ method).
So, yes, I think updating the docs to use the common terminology for both categories would be a good thing.
Cheers, Nick.
--
http://www.boredomandlaziness.org
The docs do make a distinction and generally follow the definitions given in the glossary for the tuturial.
In the case of iter(collection), I prefer the current wording because the target object need not support __iter__, it is sufficient to supply a sequential __getitem__ method.
Raymond
----- Original Message ----- From: "Calvin Spealman" ironfroggy@gmail.com To: "Python Mailing List" python-dev@python.org Sent: Wednesday, July 25, 2007 5:18 AM Subject: [Python-Dev] Terminology of "Iterable" and "Iterator"
I got into a discussion about this, which made me think it would make sense to formalize a distinction between "iterable" and "iterator". To nearly any python developer I talk with, we can define them as:
iterable - An object which can be passed to the built-in iter() function, which returns an iterator.
iterator - An object with a .next() method, which is used to invoke the iteration. An iterator _should_ also be an iterable, and will nearly always return itself as its own iterator.
Now, the current documentation makes no distinction, and we see this in the docstring for iter(), which is curious:
iter(collection) -> iterator
This might indicate that it is using "collection" where I would say "iterable". Also, the same docstring makes mention of something being an iterator _or_ a sequence, so I also should bring up that it may be antiquated, yes?
-- Read my blog! I depend on your acceptance of my opinion! I am interesting! http://ironfroggy-code.blogspot.com/
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/python%40rcn.com
Raymond Hettinger schrieb:
The docs do make a distinction and generally follow the definitions given in the glossary for the tuturial.
In the case of iter(collection), I prefer the current wording because the target object need not support __iter__, it is sufficient to supply a sequential __getitem__ method.
But as "collection" is never used in that meaning anywhere else, it could as well be iter(object).
bike-shed-ly yrs, Georg
-- Thus spake the Lord: Thou shalt indent with four spaces. No more, no less. Four shall be the number of spaces thou shalt indent, and the number of thy indenting shall be four. Eight shalt thou not indent, nor either indent thou two, excepting that thou then proceed to four. Tabs are right out.
Raymond Hettinger wrote:
In the case of iter(collection), I prefer the current wording because the target object need not support __iter__, it is sufficient to supply a sequential __getitem__ method.
Seems to me that should be included in the definition of an iterable -- i.e. anything for which iter() works is an iterable.
-- Greg