The object named 'type', in 2.2
starx at pacbell.net
Sun Feb 3 05:38:36 CET 2002
I would like to know just where i can figure out the logic behind this,
because of the name i can't seem to do a meaningful search on this. Here
is what i know:
1. In Python 2.2, there is an builtin object in python named 'type'. It
is of type 'type'.
2. Every object that the dot operator can be used on, except for classic
classes, has 'type' as it's ancestor that can be accessed through
__class__ at some level.
>>> .__class__ is type
>>> .__class__.__class__ is type
>>> class x(object): pass
>>> x.__class__ is type
>>> a = x()
>>> a.__class__ is x
>>> a.__class__.__class__ is type
>>> class y: pass
Traceback (most recent call last):
File "<pyshell#26>", line 1, in ?
AttributeError: class y has no attribute '__class__'
3. Type is it's own parent:
>>> type.__class__ is type
It is this last one particularly that I do not understand. I ran into it
today trying to fix a recrusion-death problem in PyCrust under 2.2 -- it
recursivly accesses thing's __class__es in it's attribute-finding
routines. I've tried to find information on this, but it has eluded me so
Philip Sw "Starweaver" [rasx] :: www.rubydragon.com
More information about the Python-list