More introspection in Python 2.2a2:
t = type(3) t <type 'int'>
t is a metaclass, the type of 3, i.e. an integer. You can create a new instance of an integer by calling the integer type:
t() 0 t(1) 1
These instances are type integer:
type(t(1)) <type 'int'>
But the type object that gets returned as <type 'int'> is an instance of type, a metaclass:
t.__class__ <type 'type'>
Using the introspection function from the last post:
ls(t) ['__module__', '__bases__', '__itemsize__', '__dynamic__', '__hash__', '__str__', '__weakrefoffset__', '__dict__', '__name__', '__cmp__', '__init__', '__setattr__', '__basicsize__', '__new__', '__base__', '__flags__', '__class__', '__getattr__', '__mro__', '__delattr__', 'mro', '__repr__', '__dictoffset__', '__call__', '__defined__', '__doc__']
These are the methods of the type metaclass -- nothing to do with integers per se.
t.__module__ '__builtin__'
The type metaclass is itself a subclass of a yet more generic type object.
t.__bases__ (<type 'object'>,) z = t.__bases__[0] ls(z) ['__module__', '__bases__', '__itemsize__', '__dynamic__', '__hash__', '__str__', '__weakrefoffset__', '__dict__', '__name__', '__cmp__', '__init__', '__setattr__', '__basicsize__', '__new__', '__base__', '__flags__', '__class__', '__getattr__', '__mro__', '__delattr__', 'mro', '__repr__', '__dictoffset__', '__call__', '__defined__', '__doc__']
Seems to be the same basic animal. What are __flags__ ? Hell if I know:
t.__flags__ 4603
t.__new__ <built-in method __new__ of type object at 0x80e3620>
I've been hearing about this __new__ thingy. Anyone want to elucidate? All ears. Kirby
participants (1)
-
Kirby Urner