On 11/22/2014 06:31 AM, Nick Coghlan wrote:
> 
> A particularly relevant variant of the idiom is the approach of writing
> "__iter__" directly as a generator, rather than creating a separate custom
> iterator class. In that context, the similarities between the __iter__
> implementation and the corresponding explicit __next__ implementation is a
> beneficial feature.

https://docs.python.org/3/reference/datamodel.html?highlight=__iter__#object.__iter__
--------------------------------------------------------------------------------------
> This method is called when an iterator is required for a container.
> This method should return a new iterator object that can iterate
> over all the objects in the container. For mappings, it should
> iterate over the keys of the container, and should also be made
> available as the method keys().

> Iterator objects also need to implement this method; they are
> required to return themselves. For more information on iterator
> objects, see Iterator Types.

Unless the object is itself at iterator, the __iter__ method is allowed to 
return any iterator object; whether that
iterator is constructed by a separate class entirely, or by using the iter() 
function, or by writing a generator, should
have no bearing on how we write generators themselves.

--
~Ethan~

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to