On 2007-01-09, abcd <[EMAIL PROTECTED]> wrote: > How can tell if an object is a subclass of something else? > > Imagine... > > class Thing: > pass > > class Animal: > pass > > class Dog: > pass > > d = Dog() > > I want to find out that 'd' is a Dog, Animal and Thing. Such > as... > > d is a Dog > d is a Animal > d is a Thing
isinstance(d, Dog) isinstance(d, Animal) isinstance(d, Thing) Note that in your example d is not an instance of anything but Dog. If you want a hierarchy, you must say so. Python doesn't even try to make educated guesses. class Thing: pass class Animal(Thing): pass class Dog(Animal): pass -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list