[Python-Dev] Re: copy, len and the like as 'object' methods?

Moore, Paul Paul.Moore@atosorigin.com
Thu, 23 Aug 2001 10:12:45 +0100

> I can appreciate that your tastes are different from
> mine...in fact I said something similar to David when he
> first suggested it to me but on reflection it seemed such
> a subtle thing when compared against the weirdness of the
> definition of len:
>    def len(obj):
>        return obj.__length__()
> It does a little bit more but not much!

A strange thought, but with the advent of type/class unification and the
'object' base class, is it possible to inject new methods into the 'object'
type at runtime, allowing:

    def len(self):
        return self.__length__()
    object.len = len

This would seem quite slick (or is that "sick" :-), but it makes the
language seem more mutable than might be healthy... (Or is 'object' not this
mutable...? Must try 2.2a2 and see...)