On 2/28/06, Terry Reedy <[EMAIL PROTECTED]> wrote: > > "Greg Ewing" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > And you don't think there are many different > > types of iterables? You might as well argue > > that we don't need len() because it "only > > applies to sequences". > > Since you mention it..., many people *have* asked on c.l.p why len() is a > builtin function rather than a method of sequences (and other collections) > (as .len, not .__len__). Some have suggested that it should be the latter. > The answers justifying the status quo have been twofold. > > 1. Before 2.2, not all builtin sequence types had methods (str and tuple), > so they could not have a .len method. (This begs the question of why not, > but that is moot now.)
Well, up until 2.2 you didn't have new-style classes which have a common base class. And if you wanted to do the length compilation only when requested, you needed a method. But now with object, we could add extra smarts to __getattr__ or __getattribute__ so that if ``spam.len`` is requested it calls ``spam.__next__()`` for you, basically a poor-man's property. Or, if ``spam.len`` is defined, return that. But moving over to more attributes for how we access basic interfaces seems great to me. -Brett _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com