Re: Any way of adding methods/accessors to built-in classes?

2006-10-25 Thread Tim Chase
> the builtins, but not being able to do things like > '[1,2,3]'.length drives me a little nuts. You mean like '[1,2,3]'.__len__() That gets you the length of the string, which is what one would expect, calling the __len__() method on a string. The same works for an array:

Re: Any way of adding methods/accessors to built-in classes?

2006-10-25 Thread Neil Cerutti
On 2006-10-25, [EMAIL PROTECTED] <[EMAIL PROTECTED]> 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

Re: Any way of adding methods/accessors to built-in classes?

2006-10-25 Thread Paddy
Kenneth McDonald wrote: > This is possible with pure Python classes. Just add the method as new > attribute of the class. However, that won't work for the builtins. > > I know that this is somewhat dangerous, and also that I could subclass > the builtins, but not being able to do things like '[1,2

Re: Any way of adding methods/accessors to built-in classes?

2006-10-25 Thread bearophileHUGS
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.

Any way of adding methods/accessors to built-in classes?

2006-10-25 Thread Kenneth McDonald
This is possible with pure Python classes. Just add the method as new attribute of the class. However, that won't work for the builtins. I know that this is somewhat dangerous, and also that I could subclass the builtins, but not being able to do things like '[1,2,3]'.length drives me a little