traceing object usage: how to trace attribute access
mis6 at pitt.edu
Thu Mar 6 18:09:43 CET 2003
Volker Apelt <gq437x at yahoo.de> wrote in message news:<lgvfyxaonp.fsf at mu.biosolveit.local>...
> I am looking for ways to trace all kind of access to objects
> of some class with least impact on the traced class and
> no impact on the caller.
I posted this yesterday, but didn't show up (?), therefore I will repost.
A possibility is to use properties + a custom metaclass, as in this simple
for key,value in dic.iteritems():
print "You are getting attribute %s, value=%s" % (k,v)
print "You are setting attribute %s to %s" % (k,val)
# You are getting attribute a1,value=x
# You are getting attribute a2,value=y
# You are setting attribute a1 to z
Further work is needed for tracing methods, but this should give you a
starting point. Notice that the approach works well with inheritance, except
for the tricky point that 'super' doesn't work with properties.
More information about the Python-list