Introspection

Chuck Esterbrook echuck at mindspring.com
Mon Feb 28 14:07:28 CET 2000


If I want a handle/pointer to an instance's class, how do I do that?

In Objective-C I can say:
    [someObject class]

Which in Python would be:
    someObject.class()

However, Python doesn't have a well-defined root class with such utility methods. Also, I also don't see anything useful from:
    dir(someObject)


Also, I notice the following oddity: I can use the __name__ attribute to get the name of a class, but if I say "dir(someClass)", I get attributes like __doc__ and __module__, but no __name__.  How does Python get the __name__ then?

>>> class Foo:
...     pass
...
>>> Foo.__name__
'Foo'
>>> dir(Foo)
['__doc__', '__module__']
>>>


-Chuck





More information about the Python-list mailing list