beginner ques: dir( ) does'nt list my instance methods?
Ype Kingma
ykingma at accessforall.nl
Thu Jun 21 14:50:18 EDT 2001
karthik_guru at rediffmail.com wrote:
>
> 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)?
>
You are probably looking for:
print dir(test) # the class has the methods
or, equivalently:
print dir(t.__class__)
This shows the attributes of the instance t of class test:
print dir(t)
Regards,
Ype
--
email at xs4all.nl
More information about the Python-list
mailing list