In a Python object, how can I see a list of properties that have been defined with the @property decorator?

前端 未结 4 1166
一向
一向 2020-12-30 03:42

I can see first-class member variables using self.__dict__, but I\'d like also to see a dictionary of properties, as defined with the @property decorator. How

4条回答
  •  無奈伤痛
    2020-12-30 04:12

    For an object f, this gives the list of members that are properties:

    [n for n in dir(f) if isinstance(getattr(f.__class__, n), property)]
    

提交回复
热议问题