summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2003-06-25 19:03:22 (GMT)
committerRaymond Hettinger <python@rcn.com>2003-06-25 19:03:22 (GMT)
commit2dd8c426382d620cb5aa20cf75584a174a9aacb8 (patch)
tree407f81c06b324dd984d98bc5bb34a6ee8cd2b580
parent03ec6d538af8c0f0fc49b300b0d48b98704d8f9b (diff)
downloadcpython-2dd8c426382d620cb5aa20cf75584a174a9aacb8.zip
cpython-2dd8c426382d620cb5aa20cf75584a174a9aacb8.tar.gz
cpython-2dd8c426382d620cb5aa20cf75584a174a9aacb8.tar.bz2
SF bug #696777: How to make a class iterable using a member generator.
* Added a note that a container class can implement the iterator protocol by defining its __iter__() method as a generator.
-rw-r--r--Doc/lib/libstdtypes.tex6
1 files changed, 6 insertions, 0 deletions
diff --git a/Doc/lib/libstdtypes.tex b/Doc/lib/libstdtypes.tex
index 4c1dcbd..2b64d89 100644
--- a/Doc/lib/libstdtypes.tex
+++ b/Doc/lib/libstdtypes.tex
@@ -395,6 +395,12 @@ do not obey this property are deemed broken. (This constraint
was added in Python 2.3; in Python 2.2, various iterators are
broken according to this rule.)
+Python's generators provide a convenient way to implement the
+iterator protocol. If a container object's \method{__iter__()}
+method is implemented as a generator, it will automatically
+return an iterator object (technically, a generator object)
+supplying the \method{__iter__()} and \method{next()} methods.
+
\subsection{Sequence Types \label{typesseq}}