__getattribute__ hook and len() problem

Christian Heimes lists at cheimes.de
Thu Jul 15 20:56:12 EDT 2010


> And yet, p.__len__() returns 3. I though len(object) simply
> called object.__len__.

Not exactly, all __magic__ methods of new style classes are called like
getattr(type(obj), "__len__")(obj). As a result magic methods are never
looked up on the object, including hooks like __getattr_() and
__getattribute__().

Christian




More information about the Python-list mailing list