检查类是否在类内-Python

时间:2018-10-18 17:15:59

标签: python class tree parent

我想知道一个类是否位于一个类中。

例如:

class Example:
    class InsideExample:
        pass

我想检查InsideExample是否在Example内。我该怎么办?

谢谢。

1 个答案:

答案 0 :(得分:1)

您可以将isinstanceclass一起使用,以检查该属性是否为class Example: class InsideExample: pass if hasattr(Example, 'InsideExample') and isinstance(Example.InsideExample, type): pass

<span onclick="UpdateFeatures(this,false);"> [checkbox* InterestsAndGoals id:getStartedInterestsAndGoals use_label_element "Growth" "Marketing Exposure" "Increase in overall traffic" "Edge over your competition" "Increase in low season traffic"]</span>