looking up an instance's methods
Shakeeb Alireza
sa at bayt.net
Thu Aug 9 07:58:40 EDT 2001
F:\zen>python
ActivePython 2.1.1, build 212 (ActiveState)
Python 2.1.1 (#20, Jul 26 2001, 11:38:51) [MSC 32 bit (Intel)] on
win32
Type "copyright", "credits" or "license" for more information.
>>> class Person:
... def laugh(self): pass
... def cry(self): pass
... def sleep(self): pass
...
>>> p = Person()
>>> p
<__main__.Person instance at 007E6B2C>
>>> p.__dict__
{}
>>> dir(p)
[]
>>> p.__class__.__dict__
{'__doc__': None,
'__module__': '__main__',
'cry': <function cry at 007E6FC4>,
'laugh': <function laugh at 007E5F44>,
'sleep': <function sleep at 007E70AC>}
>>>
Is there any particular reason why one can't directly introspect an
instance's methods (using dir(instance) for example) without having to
call the __dict__ namespace of its class? Is this situation likely to
change in Python 2.2?
cheers,
Shakeeb
More information about the Python-list
mailing list