[Tutor] Silly Object Namespace Questions

alan.gauld@bt.com alan.gauld@bt.com
Fri, 25 May 2001 12:00:14 +0100


> > 6. What function(s) can I use to see/list methods such as 
> "doit" within an instance?  ("vars()" and "dir()" don't do it.)

dir does but you have to use the class not the instance.
You can access the class via the __class__  attribute 
thus:

>>> class C:
...   def __init__(s): s.foo = 42
...   def sayit(s): print s.foo
...
>>> f = C()
>>> dir(f)
['foo']
>>> dir(f.__class__)
['__doc__', '__init__', '__module__', 'sayit']
>>>

Alan G