From: Raymond Hettinger Date: Wed, 25 Jun 2003 19:03:22 +0000 (+0000) Subject: SF bug #696777: How to make a class iterable using a member generator. X-Git-Tag: v2.3c1~330 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2dd8c426382d620cb5aa20cf75584a174a9aacb8;p=python 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. --- diff --git a/Doc/lib/libstdtypes.tex b/Doc/lib/libstdtypes.tex index 4c1dcbdd58..2b64d892de 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}}