dunder-docs (was Python is DOOMED! Again!)

Ian Kelly ian.g.kelly at gmail.com
Sun Feb 1 12:31:45 EST 2015


On Sun, Feb 1, 2015 at 9:55 AM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> Steven D'Aprano wrote:
>
>> len tries to call __len__ if it exists, and if not, it tries walking the
>> iterable counting items.
>
> Hmmm, I may have mis-remembered that. Perhaps I'm thinking of Ruby.

I think you just got it backward. iter will call __iter__ if it
exists, and will try to fall back on __len__ and __getitem__ to
iterate otherwise.



More information about the Python-list mailing list