[Python-3000] Builtin iterator type

Bill Janssen janssen at parc.com
Wed Nov 15 18:54:47 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

So you're suggesting something like:

   class Lengthable:

      def len(self):
         raise NotImplemented

(presumably defined in some "standard" or "builtins" module) be a
mix-in to every type which it currently makes sense to call "len()"
on?

Bill



More information about the Python-3000 mailing list