[Tutor] __iter__: one obvious way to do it
Hugo Arts
hugo.yoshi at gmail.com
Sun Mar 7 17:46:43 CET 2010
On Sun, Mar 7, 2010 at 5:37 PM, Steven D'Aprano <steve at pearwood.info> wrote:
>> "There should be one-- and preferably only one --obvious way to do
>> it" http://www.python.org/dev/peps/pep-0020/
>
> This doesn't mean that there should be *only* one way to do something.
> It means that the should be one OBVIOUS way to do it.
>
And in this case, if you consider "the thing to do" to be traversal of
some collection, the one obvious way to do it is through iteration.
So, the iterator protocol is a perfect example of this part of the
zen; the flexibility you have in implementing iteration is necessary
to allow it to be the one way.
Hugo
More information about the Tutor
mailing list