type, object hierarchy?

Steve Holden steve at holdenweb.com
Mon Feb 4 22:46:47 CET 2008

Christian Heimes wrote:
> 7stud wrote:
>> The output suggests that Dog actually is a subclass of type--despite
>> the fact that issubclass(Dog, type) returns False.  In addition, the
>> output of dir(type) and dir(object):
> No, type is the meta class of the class object:
>>>> issubclass(object, type)
> False
>>>> isinstance(object, type)
> True
> As you can see object is not a subclass of type but an instance of type.
> This may look confusing at first but it's easy to explain. Like a class
> is the blue print of an instance, a meta class is the blue print of a
> class. In Python everything is a direct or indirect instance of type.
This might be helpful is the phrase "indirect instance" had any meaning 
whatseover ;-)

> o = someobject
> while o is not type:
>     o = type(o)
>     print o
> The code will eventually print "type".
Except, of course, when someobject is type, when it won't print anything 
at all.

Steve Holden        +1 571 484 6266   +1 800 494 3119
Holden Web LLC              http://www.holdenweb.com/

More information about the Python-list mailing list