All functions from self and inherited classes

Christer Østergaard wintedk at hotmail.com
Tue Jun 12 14:35:27 EDT 2001


Hey all!

I'm currently working on creating a general class (GeneralClass), that has
public method named doc().

I have the following inheritance setup: GeneralClass -> A -> B

When i create an instance of B, namely b, and call b.doc(), I want to
display all methods from self (that's b) including inherited methods (from
GeneralClass and A). But... no toast for monty!

My code in GeneralClass .doc() is this:
aClass = getattr(self, "__class__")
print getattr(aClass, "__bases__")

Line one finds the class from which self was instanciated from, right? The
second should find all bases for that class... My intention is to iterate
through all in bases, running dir() on each of them, and thereby getting all
methods and compile a list. On that list I want to write all __doc__, and
thereby create a function, which returns full documentation. No matter what
I do, I cannot get anything from bases. And a dir(self.__class__) returns
methods, but only methods defined in B.

I've tried this "outside" (in Python interactive mode), and it works (in an
alternate version, though) on any class... but in some way, when called from
from within a class method, the scope of the class method makes some
changes?

Please advice me on how to get all methods available for a given class... i
promise to follow up and post the entire solution when i get there!

Thanks in advance!

Christer / Denmark







More information about the Python-list mailing list