Can a descriptor be assigned to an instance attribute instead of a class attribute?

Viewed 43

I am looking into Python descriptors. So far, all of the examples I have found on Google assign a descriptor object only class attributes.

Should a descriptor be always be assigned to a class attribute? Can a descriptor be assigned to an instance attribute? If so, any examples or use cases?

For example, all examples are like:

>>> class MyClass(object):  
    x = RevealAccess(10, 'var "x"')  
    y = 5 

Can we have something like:

>>> class MyClass(object):  
    init(self ):  
        x = RevealAccess(10, 'var "x"')  
        y = 5
0 Answers
Related