Python中的描述符是一个相对底层的概念 descriptor Any object which defines the methods get(), set(), or delete(). When a class attribute is a descriptor, its special binding behavior is triggered upon attribute lookup. Normally, using a.b to get, set or delete an att…
Python的描述符乍眼看去简单,但是细节方面如果不注意容易掉坑,总结以下几个坑,以作备忘,先看代码: class D: def __get__(self, inst, owner): if inst is None: return self else: print('I am in the D.__get__') return inst.__dict__['d'] # 返回实例的d属性 def __set__(self, inst, value): if not isinstance(valu…