I need to list all the attribute of a class that are properties and have a setter. For example with this class:
class MyClass(object):
def __init__(self):
self. a = 1
self._b = 2
self._c = 3
@property
def b(self):
return self._b
@property
def c(self):
return self._c
@c.setter
def c(self, value):
self._c = value
I need to get the attribute c but not a and b. Using this answers: https://stackoverflow.com/a/5876258/7529716 i can get the property object b and c.
But is their a way to know if those properties have a setter other than trying:
inst = MyClass()
try:
prev = inst.b
inst.b = None
except AttributeError:
pass # No setter
finally:
inst.b = prev
Thanks in advance.