[Python-Dev] defaultdict and on_missing()

Brett Cannon brett at python.org
Wed Mar 1 20:02:19 CET 2006


On 2/28/06, Terry Reedy <tjreedy at udel.edu> wrote:
>
> "Greg Ewing" <greg.ewing at canterbury.ac.nz> wrote in message
> news:44052636.9090709 at canterbury.ac.nz...
> > 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


More information about the Python-Dev mailing list