Working Notes: a commonplace notebook for recording & exploring ideas.
Home. Site Map. Subscribe. More at expLog.
Python/Descriptors
- #+title: Python/Descriptors
- Described in the datamodel: https://docs.python.org/3/reference/datamodel.html
- Applied when instance of class containing the method == descriptor, appears in an owner class
- =get= get value of attribute for instance or class
- =set= set value of instance (data descriptor)
- =delete= delete attribute on instance
- "Descriptor" is an object attribute with binding behavior
- =a.x=
- == =x.get(a)=
- == =type(a).dict['x'].get(a, type(a))=
- etc.
- No get means it returns the object itself
- =@staticmethod= & =@classmethod= are non-data descriptors
- Non-data descriptors can be overridden
**
— Kunal