All functions from self and inherited classes

Alex new_name at mit.edu
Tue Jun 12 15:16:30 EDT 2001


> And a dir(self.__class__) returns methods, but only methods defined in
> B.

Someone posted this code here ages ago.  It should give you all of B's
methods, I guess.

def unique(seq):
    out = []
    if len(seq):
        out.append(seq[0])
        for i in range(1,len(seq)):
            if seq[i] != seq[i-1]:
                out.append(seq[i])
    return out

def megadir(obj = globals()):
    ldir = []
    for b in getattr(obj, '__bases__', []):
        ldir.extend(megadir(b))
    if type(obj) == types.InstanceType:
        ldir.extend( megadir(obj.__class__) )
    ldir.extend(dir(obj))
    ldir.sort()
    return unique(ldir)

HTH.
Alex.



More information about the Python-list mailing list