An Object's Type
Christian Heimes
lists at cheimes.de
Wed Dec 5 08:05:32 EST 2007
bg_ie at yahoo.com wrote:
> Hi,
>
> Is it possible to find out if an object is of a certain type or of a
> type derived from this type?
class Example(object):
pass
class AnotherExample(Example):
pass
>>> issubclass(Example, object)
True
>>> issubclass(AnotherExample, object)
True
>>> issubclass(AnotherExample, Example)
True
>>> issubclass(Example, AnotherExample)
False
And finally
>>> isinstance(Example, type)
True
This is true because type is the metaclass of object. Though you don't
have to understand it. ;)
Christian
More information about the Python-list
mailing list