class obj(object):
    def __getattribute__(self, *args, **kwargs): # 访问属性就会被调用
        print("__getattribute__() is called")
        return object.__getattribute__(self, *args, **kwargs)

    def __getattr__(self, name): # 类实例访问不存在的属性时会被调用
        print("__getattr__() is called ")
        return name + " from getattr"

    def __get__(self, instance, owner): # 成为描述者身份,当此类的实例作为其他类的属性值时会被调用
        print("__get__() is called", instance, owner)
        return self

 

posted on 2015-11-05 16:07  浊浊然  阅读(148)  评论(0编辑  收藏  举报