Any way of adding methods/accessors to built-in classes?
Kenneth McDonald
kenneth.m.mcdonald at sbcglobal.net
Wed Oct 25 15:42:56 EDT 2006
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 nuts. Python is about the only computer language I
use, and I think it's certainly the best of the scripting languages, but
there are inconsistencies in the object model and some other things I
wish I could fix. If could could modify the builtins this way, I'd be
willing to take the risk.
Thanks,
Ken
More information about the Python-list
mailing list