Python 父对象中的self.\u dict\u\dict没有子属性?

Python 父对象中的self.\u dict\u\dict没有子属性?,python,inheritance,Python,Inheritance,我有两门课: class Base(object): def __init__(self): object.__init__(self) def print_methods(self): print self.__dict__ class Child(Base): def __init__(self): Base.__init__(self) def another_method(self): pass 现在我可以在子实例中调用pr

我有两门课:

class Base(object):
  def __init__(self):
    object.__init__(self)

  def print_methods(self):
    print self.__dict__

class Child(Base):
   def __init__(self):
     Base.__init__(self)

   def another_method(self):
     pass

现在我可以在
子实例中调用
print\u方法
,并希望看到
另一个\u方法
。但是失败了。

这与继承毫无关系
Child。另一个方法()
是类的属性,而不是实例,因此它不在
self
目录中,而是在
Child
目录中。如果仅创建
Base
的实例并在此实例上调用
print\u methods()
,则也不会看到
print\u methods

要查找实例的所有方法,可以使用
dir()
inspect.getmembers()
(可以与
callable()
结合使用,仅包括可调用属性)