The object named 'type', in 2.2
Jason Orendorff
jason at jorendorff.com
Sun Feb 3 01:26:42 EST 2002
Philip Swartzleonard writes:
> 3. Type is it's own parent:
>
> >>> type.__class__ is type
> 1
>
> It is this last one particularly that I do not understand.
Well, the type of TypeType has always been itself. For a long
time, it's been like this:
type(3) is types.IntType
type(types.IntType) is types.TypeType
type(types.TypeType) is types.TypeType
It's the same today, except for two things:
1. type (like str, int, list, etc.) used to be just a function.
Now it is a type. But (like str, int, list, etc.) it still
works if you call it as a function, just like the old way.
2. Now a bunch more objects have a nice x.__class__ attribute
that is the same thing as type(x).
> 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
> far...
I don't know where you can find more information, sorry.
It might be that recursively looking at __class__es is not what
you want after all; maybe you should walk x.__class__.__bases__
instead.
## Jason Orendorff http://www.jorendorff.com/
More information about the Python-list
mailing list