http://www.cnblogs.com/linhaifeng/articles/6204014.html#_label12

描述符是什么:描述符本质就是一个新式类,在这个新式类中,至少实现了__get__(),__set__(),__delete__()中的一个,这也被称为描述符协议
__get__():调用一个属性时,触发
__set__():为一个属性赋值时,触发
__delete__():采用del删除属性时,触发

定义一个描述符

 

class Foo: #在python3中Foo是新式类,它实现了三种方法,这个类就被称作一个描述符
    def __get__(self, instance, owner):
        pass
    def __set__(self, instance, value):
        pass
    def __delete__(self, instance):
        pass
View Code

相关文章:

  • 2021-07-29
  • 2021-08-05
  • 2022-02-24
  • 2018-10-11
  • 2022-12-23
  • 2021-10-27
  • 2021-06-20
  • 2022-01-20
猜你喜欢
  • 2022-12-23
  • 2022-02-25
  • 2019-03-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案