[Tutor] adding methods to native types
Erik Price
erikprice@mac.com
Thu Feb 6 08:10:01 2003
On Thursday, February 6, 2003, at 12:20 AM, Sean 'Shaleh' Perry wrote:
> easy answer: it has been that way since Python began.
>
> much of python lets you interact with objects without actually using
> methods.
> I think len() is one of those vestiges.
>
> I wonder if it had something to do with trying to ease people into OO
> (Python
> was meant to help those learning programming).
Okay. So there's nothing wrong with doing:
class MyList():
def __init__(self):
self._mylist = []
def len(self):
return len(self)
?
It feels "dirty" to use the __init__ method since it has those magic
underscores (I feel the same way about using if __name__ ==
"__main__"). But there is no other name for the constructor, right?
Erik
--
Erik Price
email: erikprice@mac.com
jabber: erikprice@jabber.org