beginner ques: dir( ) does'nt list my instance methods?

karthik_guru at rediffmail.com karthik_guru at rediffmail.com
Wed Jun 20 04:55:12 EDT 2001


class test:
    def __init__(self):
        print 'hello test'
        self.foo = 100
        self.bar = 900
        
    def func(self):
        print 'hello'


if __name__ == '__main__':
    t = test()    
    print dir(t)
    print t.__dict__

Both dir(t) and t.__dict__ print only foo and bar.
They don't print the func which is also a instance attribute (method 
reference)?

But they are printed when i do test.__dict__ and dir(test)..ie 
<classname>
why is it not getting printed in the earlier case?(wiht instance)

I might be required to do a look up from dir(instance) and if an 
attribute happens to be of the type method i can invoke it?

thanks
karthik.





More information about the Python-list mailing list