Behaviour of classes (tired of writing too much)

mpn at mic.dtu.dk mpn at mic.dtu.dk
Mon Sep 11 11:54:00 EDT 2006


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)

The reason for the question is that I want to simplify the Message
Passing Interface (MPI) calls. I find it irritating that I have to
start a non-blocking send/receive and then check that the data has
arrived. Why not automagically check/wait for the data when it is
needed?

The second part that I also need to make that idea work is the ability
to change the instance to the received data, i.e., self=received data,
and then launch the original reference.

So I guess that the code I want to write is:

class MPI_tmp:
       # temporary object that changes ITSELF into another object when
called in any way
       def __on_any_call__(self):
               self=newobject()
               self.__run_the_anycall__()

which probably doesn't work :-)

Greatful for any ideas / Magnus




More information about the Python-list mailing list