runtime type information in python?

Erik Max Francis max at alcyone.com
Wed Aug 23 01:31:39 EDT 2000


Issac Trotts wrote:

> Suppose I execute the following code:
> 
> class C: pass
> class B(C): pass
> b=B();
> 
> How do I find out what kind of object b is?

    if b.__class__ is B:
        ...

> How can I find out whether b is-a C?

    if isinstance(b, C):
        ...

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE
/  \ Then conquer we must, for our cause is just ...
\__/ Francis Scott Key
    Alcyone Systems' CatCam / http://www.catcam.com/
 What do your pets do all day while you're at work?  Find out.



More information about the Python-list mailing list