On 10/29/2011 05:20 AM, Ethan Furman wrote:

Python only looks up __xxx__ methods in new-style classes on the class
itself, not on the instances.

So this works:

8<----------------------------------------------------------------
class Cow(object):
pass

def attrgetter(self, a):
print "CAUGHT: Attempting to get attribute", a

bessie = Cow()

Cow.__getattr__ = attrgetter

print bessie.milk
8<----------------------------------------------------------------

a minor modification might be useful:

bessie = Cow()
bessie.__class__.__getattr__ = attrgetter


--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to