This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2010年11月13日 19:18 by methane, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Messages (4) | |||
|---|---|---|---|
| msg121152 - (view) | Author: Inada Naoki (methane) * (Python committer) | Date: 2010年11月13日 19:18 | |
In http://docs.python.org/release/2.6.6/glossary.html, "iterable" is described as "A container object capable of returning its members one at a time." Is it correct? Is stream object like file a container type? Container ABC requires only "__contains__" abstract method. I think file is iterable but is not container. Likewise, "and objects of any classes you define with an __iter__() or __getitem__() method." is wrong because __getitem__ method is not relate to iterable. |
|||
| msg121166 - (view) | Author: Raymond Hettinger (rhettinger) * (Python committer) | Date: 2010年11月13日 23:51 | |
> "iterable" is described as "A container object > capable of returning its members one at a time." That wording is confusing. I'll fix it. > Likewise, "and objects of any classes you define > with an __iter__() or __getitem__() method." is > wrong because __getitem__ method is not relate to > iterable That wording is correct. Sequences are automatically iterable even if they don't define __iter__. For example: >>> class A: ... def __getitem__(self, i): ... if i > 10: ... raise IndexError(i) ... return i * 100 >>> list(A()) [0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000] If you're curious, the details are in the PyObject_GetIter() function in http://svn.python.org/view/python/branches/release27-maint/Objects/abstract.c?view=markup . |
|||
| msg121175 - (view) | Author: Raymond Hettinger (rhettinger) * (Python committer) | Date: 2010年11月14日 05:27 | |
Removed the incorrect "container" reference. See r86463. |
|||
| msg121184 - (view) | Author: Inada Naoki (methane) * (Python committer) | Date: 2010年11月14日 10:25 | |
>> Likewise, "and objects of any classes you define >> with an __iter__() or __getitem__() method." is >> wrong because __getitem__ method is not relate to >> iterable > > That wording is correct. Sequences are automatically > iterable even if they don't define __iter__. For example: Wow, thank you! |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:08 | admin | set | github: 54619 |
| 2010年11月14日 10:25:23 | methane | set | messages: + msg121184 |
| 2010年11月14日 05:27:56 | rhettinger | set | status: open -> closed resolution: fixed messages: + msg121175 |
| 2010年11月13日 23:51:22 | rhettinger | set | priority: normal -> low messages: + msg121166 |
| 2010年11月13日 23:41:30 | rhettinger | set | assignee: docs@python -> rhettinger nosy: + rhettinger |
| 2010年11月13日 19:18:27 | methane | create | |