© Jacob Zimmerman 2018
Jacob ZimmermanPython Descriptorshttps://doi.org/10.1007/978-1-4842-3727-4_7

7. Storing the Attributes

Jacob Zimmerman1 
(1)
New York, USA
 

Now that all the preliminaries are out of the way, it is time to see the part of descriptors that is useful: storing the attributes that the descriptor represents. There are a lot of ways to store attributes with a descriptor, and this chapter will go over every option that I’m aware of, starting with the easiest.

Class-Level Storage

Class-level storage is easy; it’s normal storage on the descriptor. As an example, here is a descriptor that creates a basic class-level variable:
class ClassAttr:
    def __init__(self, value):
        self.value = value
    def __get__(self, instance, owner):
        return ...

Get Python Descriptors: Understanding and Using the Descriptor Protocol now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.