How do I check if a property is settable or deletable in Python?
The best I've found so far is
type(obj).__dict__["prop_name"].fset is not None
This is a good case when you should subscribe to "It's Easier to Ask for Forgiveness than Permission" philosophy, and just handle the exception in case property is not settable/deletable.
try:
x.prop = 42
except AttributeError:
pass
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With