a small doubt

Piyush Anonymous piyush.subscription at gmail.com
Sun Dec 21 02:50:24 CET 2008


i wrote this code
--
class Person(object):
    instancesCount = 0
    def __init__(self, title=""):
        Person.instancesCount += 1
        self.id = "tempst"
    def testprint(self):
        print "blah blah"
    def __getattribute__(self, name):
        print "in get attribute"

a = Person()
a.testprint()
print 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?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20081221/7be9793a/attachment.html>


More information about the Python-list mailing list