Getting a list of ALL functions in a class

Fredrik Lundh effbot at
Fri Mar 10 00:49:52 CET 2000

Eric Hopper <eric.hopper at> wrote:
> I want to get a dictionary of all functions accessible in a class.
> Doing <class>.__dict__ only gets me the functions defined in that class,
> not any of it's base classes.
> Is there a way to do this simply, or do I have to use __base__ to write
> my own scanner?

or you can cut and paste from this eff-bot guide


class A:
    def a(self):
    def b(self):

class B(A):
    def c(self):
    def d(self):

def getmembers(klass, members=None):
    # get a list of all class members
    if members is None:
        members = []
    for k in klass.__bases__:
        getmembers(k, members)
    for m in dir(klass):
        if m not in members:
    return members

print getmembers(A)
print getmembers(B)
print getmembers(IOError)

## running this will print:
## ['__doc__', '__module__', 'a', 'b']
## ['__doc__', '__module__', 'a', 'b', 'c', 'd']
## ['__doc__', '__getitem__', '__init__', '__module__', '__str__']


<!-- (the eff-bot guide to) the standard python library:

More information about the Python-list mailing list