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

laotseu bdesth at removethis.free.fr
Thu Jan 23 18:15:06 EST 2003


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
> 

You already got answers to your questions, so I just ask you one : why 
do you (think you) need to control the class of an object ?

If it's just to be sure it expose whole or part of a given interface, it 
may not be the most pythonic thing to do IMHO. Doing so you're loosing 
all the advantages of dynamic typing when it comes to polymorphism.

(but you may have other good reasons to do so ?)

<OT>
Ok, I know that's not what the OP was asking for, but I did this kind of 
things when I started learning Python, before realising it was not such 
a good thing).
</OT>

Laotseu





More information about the Python-list mailing list