> 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:
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
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
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.
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