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

Guido van Rossum guido@python.org
Thu, 23 Aug 2001 09:24:52 -0400


> 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

No you can't.  Built-in types are immutable.  Two reasons: they're
shared between multiple interpreters, and it would encourage modules
to modify a built-in type to suit their own needs, which it might
break other modules.

--Guido van Rossum (home page: http://www.python.org/~guido/)