Is there a way to access __dict__ (or something like it) that includes base classes?

前端 未结 5 846
南旧
南旧 2020-12-20 12:42

Suppose we have the following class hierarchy:

class ClassA:

    @property
    def foo(self): return \"hello\"

class ClassB(ClassA):

    @property
    def         


        
5条回答
  •  伪装坚强ぢ
    2020-12-20 12:54

    {k: getattr(ClassB, k) for k in dir(ClassB)}
    

    Proper values (instead of ) will be presented when using ClassB instance.

    And of course You can filter this by adding things like if not k.startswith('__') in the end.

提交回复
热议问题