Behaviour of classes (tired of writing too much)

Brian Quinlan brian at sweetapp.com
Mon Sep 11 12:13:57 EDT 2006


mpn at mic.dtu.dk wrote:
> How do I catch any reference to an instance of a class, i.e., I want to
> run some code as soon as an instance of a class is used in any way.
> (and I don't want to define all of __add__, __ge__ etc etc etc etc etc)

What do you mean by "used in any way"? Which of these are considered usage:

 >>> a = Foo()   # obviously
 >>> b = a       # ?
 >>> a.__gt__(5) # apparently
 >>> a.__gt__    # ?

Anyway, look into __getattr__

Cheers,
Brian



More information about the Python-list mailing list