How to get the types of the parents of an object ?

Mike C. Fletcher mcfletch at rogers.com
Tue Jan 21 13:42:01 CET 2003


Finding object/class inheritence is common enough to have two builtin 
functions assigned to the task:

    isinstance( my_object, my_super_class )

    issubclass( my_class, my_super_class )

and, under Python 2.2, you can do silly things like:

    my_super_class in my_class.__mro__

Though that last one is almost certainly _not_ a good idea :) .  I'm 
just providing it to give you pointers as to things to search for in the 
docs if you really do want to get all super-classes (parents) of a 
class.  You could also search for __bases__ for the older Python 
versions (still available in 2.2, just not as convenient as __mro__).

Enjoy,
Mike

christophe grimault wrote:

> Hi,
>
> I need to control the type of some arguments passed to a constructor. 
> Specifically,
> my classes inherit of 'object', so
>
> type(my_object)
>
> returns
>
> my_class
>
> Now my_class is a child of my_super_class. And I want to check if
> my_object is an instance of my_super_class.
>
> How can I do that
>
> Thanks in advance,
>
> Chris
>

-- 
_______________________________________
  Mike C. Fletcher
  Designer, VR Plumber, Coder
  http://members.rogers.com/mcfletch/








More information about the Python-list mailing list