Any way of adding methods/accessors to built-in classes?
horpner at yahoo.com
Wed Oct 25 22:14:26 CEST 2006
On 2006-10-25, bearophileHUGS at lycos.com <bearophileHUGS at lycos.com> wrote:
> Kenneth McDonald:
>> not being able to do things like '[1,2,3]'.length
>> drives me a little nuts.
> This is interesting, why?
> (In a computer language too much purity is often bad. And isn't
> [1,2,3].len better?)
> I think you can't add methods to Python builtin classes, I
> think you can do it with Ruby.
You can create derived versions of builtins with new methods
(which affords the benefits of modifying builtins), but
you can't change the type of a Python literal. So the above would
More information about the Python-list