How to bound a method to a instance ?

Maarten van Reeuwijk maarten at remove_this_ws.tn.tudelft.nl
Wed Feb 11 02:56:59 EST 2004


"Martin v. Löwis" wrote:

> Emmanuel wrote:
>> main module :
>> --------------
>> import toto
>> 
>> a = toto.toto()
>> a.method() -> does something ...
>> 
>> reload (toto)
>> now a is not reloaded...
>> 
>> a.method = toto.toto().method
>> does not work, because a.method would be bounded to a new instance...
> 
> It might be best to change the class of a:
> 
> reload (toto)
> a.__class__ = toto.toto

Thank you emmanuel for asking this question, I was wondering exactly the
same thing. Is it also possible to override the reload method to make it
(besides reloading) to scan through all namespaces for objects of class
toto.toto and replace their methods automatically? What would that code
look like?

Thanks, 

Maarten

-- 
===================================================================
Maarten van Reeuwijk                    Thermal and Fluids Sciences
Phd student                             dept. of Multiscale Physics
www.ws.tn.tudelft.nl                 Delft University of Technology



More information about the Python-list mailing list