How to examine the inheritance of a class?

John Ladasky ladasky at my-deja.com
Thu Oct 23 21:36:46 EDT 2008


Hello again!

Suppose that I have several subclasses which inherit from a base
class, thus:

class Foo(object):

class Spam1(Foo):

class Spam2(Foo):

class Spam3(Foo):

etc.  The list of subclasses is not fully defined.  It is supposed to
be extensible by the user.

Many methods will differ between these classes.  However, there are
operations which may be performed between two Foo objects, OR between
any of Foo's derivatives.

There are instances where I would like to perform type checking before
carrying out the operation.  Rather than having to enumerate all of
Foo's subclasses (which would defeat my intent of extending the list
of subclasses anyway), I would like to see whether a class is DERIVED
from Foo.  Where is this information stored in the class definition?

Thanks!




More information about the Python-list mailing list