Descriptors in python
Descriptor: a word or expression used to describe or identify something.
In python, descriptors are written to customized access of an object’s attribute. It involves three actions get, set and delete. Which are implemented using special
__delete__ functions respectively.
__get__: access the object’s instance value and returns it.
__set__: set object’s instance value and return nothing.
__delete__: delete object’s instance value and returns nothing.
Below is the example of a basic descriptor class.
class SimpleDescriptor(object): def __get__(self, instance, owner): """ :param instance: self variable of the object being updated. :param owner: owning class object :return: None """ return self.__dict__[instance] def __set__(self, instance, val): """ :param instance: self variable of the
Continue reading →