a small doubt
MRAB
google at mrabarnett.plus.com
Sat Dec 20 21:36:52 EST 2008
Piyush Anonymous wrote:
> i wrote this code
> --
> class Person(object):
> instancesCount = 0
> def __init__(self, title=""):
> Person.instancesCount += 1
> self.id <http://self.id> = "tempst"
> def testprint(self):
> print "blah blah"
> def __getattribute__(self, name):
> print "in get attribute"
>
> a = Person()
> a.testprint()
> print a.id <http://a.id>
> -----
> but i am getting this error
> ----
> in get attribute
> Traceback (most recent call last):
> File "trapmethodcall1.py", line 15, in <module>
> a.testprint()
> TypeError: 'NoneType' object is not callable
> ------
> why is it so? __getattribute__ is called whenever an attribute or method
> is called, rt? or if i set __getattribute__ , i cannot have methods in
> class?
>
> actually my aim is to trap all method calls and keep a counter which is
> update whenever method called or returned. how should i go about it?
>
a.testprint causes __getattribute__ to be called. That method returns
None. a.testprint() is therefore None(), hence the exception.
More information about the Python-list
mailing list