[Python-3000] Builtin iterator type

George Sakkis george.sakkis at gmail.com
Wed Nov 15 10:40:12 CET 2006


Fredrik Lundh <fredrik at pythonware.com> wrote:

> George Sakkis wrote:
>
> > 1) why having a "generic operation" len() that ends up looking for an
> > ugly special *method* called  __len__() makes sense, while calling
> > directly a method len() doesn't
>
> for the very reason Mike explained: keeping implementation interfaces
> separate from public interfaces has allowed Python to avoid a certain
> category of design fragmentation that other languages suffer from.

Fredrik, I am not arguing for the argument's sake, I just don't get
it: Python requires my class to define __len__, otherwise len() fails.
Why not require len() as a method instead and forget about __len__ ?
Does len() (the function) do anything smarter behind the scenes than
just passing the ball to __len__ ? That could justify its role but
AFAIK it doesn't.

George


More information about the Python-3000 mailing list