0

I want to get all the properties of an object, and with this I mean only methods decorated with @property.

Answers to similar questions like here return all attributes and/or methods without filtering those which are properties.

user171780
  • 2,243
  • 1
  • 20
  • 43
  • What happened when you tried using one of those methods, and then filtering to check which of the attributes are properties? (Hint: `property` is itself a *class*, so you can simply use type-checking.) – Karl Knechtel Jul 07 '21 at 10:03
  • That said, I think that answering this question will not be as useful to you as you expect. – Karl Knechtel Jul 07 '21 at 10:04
  • Thanks. I am trying this `[attr for attr in dir(object) if isinstance(getattr(object,attr),type(property))]` but it is not working. It only returns `['__doc__', '__module__']` and this object has properties I have defined. – user171780 Jul 07 '21 at 10:10

1 Answers1

-1

I don't know what is the expected result you want, but you can filter the methods that are from the class property. For example:

class A:

    def bla(self):
        pass

    @property
    def ble(self):
        pass

list(
    filter(
        lambda f: isinstance(f[1], property),
        vars(A).items()
    )
)

# Result
# [('ble', <property at 0x7f01149074a8>)]
hyper7
  • 171
  • 8