Le Jeudi 08 Juin 2006 14:28, Ilias Lazaridis a écrit :
> Another possibility is to enlink (hook?) the functionality into an
> existent function
>
> Is there any way (beside a patch) to alter the behaviour to an existing
> function. Is ther a python construct similar to the "alias_method" of Ruby:
>
No, there is no special construct to do this, but we do things very similar 
every day in Zope, it's called "monkey patch" :

#patch_service.py
from toto import service

def my_impl(self, *args) :
        old_result = self._old_method(*args)
        # ...
        return new_result

if not hasattr(service, '_old_method') :
        service._old_method = service.method
        service.method = my_impl

once this file is imported, all future calls to "method" of service instances 
will use my_impl.

-- 
_____________

Maric Michaud
_____________

Aristote - www.aristote.info
3 place des tapis
69004 Lyon
Tel: +33 426 880 097
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to