I have two classes:
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
Now I can to call the print_method in a Child instance, and expecting to see the another_method. But failed.
This is not related to inheritance at all.
Child.another_method()is an attribute of the class, not the instance, so it’s not in the__dict__ofself, but rather in the dict ofChild. If you create an instance ofBaseonly and callprint_methods()on this instance, you won’t seeprint_methodsas well.To find all methods of an instance, you can use
dir()orinspect.getmembers()(possible in combination withcallable()to only include the callable attributes).